I am trying to use scriptcs 0.17.1 to create a simple script in C#. Here's my script:
using System.Data;
using(var connection = new SqlConnection("constring"))
{
using(var command = new SqlCommand("select GETDATE()", connection))
{
connection.Open();
command.ExecuteNonQuery();
Console.WriteLine("Hello, world!");
}
}
When I run via scriptcs test.csx
this gives me the error:
CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
According to the documentation:
System, System.Core, System.Data, System.Data.DataSetExtensions, System.Xml, System.Xml.Linq assemblies are referenced by default.
I tried adding the following line to the top of my script but got the same error:
#r "System.Data.dll"
I tried fully qualifying my class name as System.Data.SqlConnection
but got the same error.
I have verified that System.Data.dll exists in the GAC at C:\Windows\Microsoft.NET\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089
and C:\Windows\Microsoft.NET\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089
Normal .NET console applications (non-scriptcs) have no issue using the SqlConnection class.
You don't have the correct namespace. The SqlConnection
class is actually in System.Data.SqlClient