I ran into this myself a couple of months ago and decided to write a short blog post about it in case you happen to run into this. SQL Server 2008 lets you use Visual Basic or C# as the scripting language in a Script Task. If you decided to translate some of your older packages from VB to C# be aware that there are some subtle differences and things don’t translate one to one.

If this is your code in Visual Basic

Dim FileName As String
 FileName = (Dts.Variables("varFileName").Value).ToString()


And if you change it to this in C#

string FileName;
FileName = (Dts.Variables("varFileName").Value).ToString();


You will get the following friendly error.

Non-invocable member ‘Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel.Variables’ cannot be used like a method.

Do you see what the error is in the code?

In C# you need to use brackets, not parentheses so instead of the top line of code, you need to use the bottom one



Here is the code block in C#

string FileName;
FileName = (Dts.Variables["varFileName"].Value).ToString();


*** Remember, if you have a SQL related question, try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum