If you are using Beta 2, then try this code to connect to your SQL server.
Some words about connect string: Persist Security Info can not be omitted.Data
Source is your SQL server name, not ODBC DNS name!(if you run SQL locally, put
your cursor over the icon on system toolbar , you will see "\\XXXXX", that
XXXXX is your server name).
using System;
using System.Data.OleDb;
class OleDbTest{
public static void Main()
{
OleDbConnection? aConnection = new OleDbConnection(\"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=masterjy\");
OleDbCommand? aCommand = new OleDbCommand(\"select * from orders\", aConnection);
try{
aConnection.Open();
OleDbDataReader? aReader = aCommand.ExecuteReader();
Console.WriteLine(\"This is the returned data from Northwind's Orders table\");
while(aReader.Read()){
Console.WriteLine(aReader.GetInt32(0).ToString());
}
aReader.Close();
aConnection.Close();
}
catch(OleDbException e)
{
Console.WriteLine(\"Error: {0}\", e.Errors0.Message);
}
}
}
0 comments:
Post a Comment