oledb 方式连接
1 class Program 2 { 3 private static string constr = "server=.;database=northwnd;integrated security=sspi"; 4 static void Main(string[] args) 5 { 6 string source = "provider=sqloledb;" + constr; 7 string select = "select contactname,companyname from customers"; 8 OleDbConnection con = new OleDbConnection(source); 9 con.Open(); 10 OleDbCommand cmd = new OleDbCommand(select, con); 11 OleDbDataReader reader = cmd.ExecuteReader(); 12 while (reader.Read()) 13 Console.WriteLine("{0} from {1}", reader.GetString(0), reader.GetString(1)); 14 reader.Close(); 15 con.Close(); 16 } 17 18 }