using System.Data.Odbc;
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
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();
// .NET Data Provider -- Default Relative Path
// Standard Connection |
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"User Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
// .NET Data Provider -- Default Relative Path
// Trusted Connection |
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString =
"Data Source=.\SQLExpress;" +
"User Instance=true;" +
"Integrated Security=true;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open(); |
|
|
|
No comments:
Post a Comment