本文共 3813 字,大约阅读时间需要 12 分钟。
// ODBC DSN using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName;" + "Uid=UserName;" + "Pwd=Secret;"; conn.Open();
// ODBC -- Standard Connection using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=ServerName;" + "DataBase=DataBaseName;" + "Uid=UserName;" + "Pwd=Secret;"; conn.Open();
// ODBC -- Trusted Connection using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=ServerName;" + "DataBase=DataBaseName;" + "Uid=xxxxxx;" + "Pwd=xxxxxx;"; conn.Open(); // or OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=ServerName;" + "DataBase=DataBaseName;" + "Trusted_Connection=Yes;"; conn.Open();
// OleDb -- Standard Connection using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;"; conn.Open();
// OleDb -- Trusted Connection using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "Integrated Security=SSPI;"; conn.Open();
// OleDb -- via IP Address using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Network Library=DBMSSOCN;" + "Data Source=xxx.xxx.xxx.xxx,1433;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;"; conn.Open();
// .NET DataProvider -- Standard Connection using System.Data.SqlClient; SqlConnection conn = new SqlDbConnection(); conn.ConnectionString = "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;"; conn.Open();
// .NET DataProvider -- Trusted Connection using System.Data.SqlClient; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "Integrated Security=SSPI;"; conn.Open();
// .NET DataProvider -- via IP Address using System.Data.SqlClient; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Network Library=DBMSSOCN;" + "Data Source=xxx.xxx.xxx.xxx,1433;" + "Initial Catalog=DataBaseName;" + "User Id=UserName;" + "Password=Secret;"; conn.Open();
转载地址:http://hotqj.baihongyu.com/