connectionstring در سی شارپ
// ODBC DSN
usingSystem.Data.Odbc;
OdbcConnectionconn = new OdbcConnection();
conn.ConnectionString=
“Dsn=DsnName;” +
“Uid=UserName;” +
“Pwd=Secret;”;
conn.Open();
// ODBC –Standard Connection
usingSystem.Data.Odbc;
OdbcConnectionconn = new OdbcConnection();
conn.ConnectionString=
“Driver={SQL Server};”+
“Server=ServerName;” +
“DataBase=DataBaseName;” +
“Uid=UserName;” +
“Pwd=Secret;”;
conn.Open();
// ODBC –Trusted Connection
usingSystem.Data.Odbc;
OdbcConnectionconn = new OdbcConnection();
conn.ConnectionString=
“Driver={SQL Server};”+
“Server=ServerName;” +
“DataBase=DataBaseName;” +
“Uid=;” +
“Pwd=;”;
conn.Open();
// or
OdbcConnectionconn = new OdbcConnection();
conn.ConnectionString=
“Driver={SQL Server};”+
“Server=ServerName;” +
“DataBase=DataBaseName;” +
“Trusted_Connection=Yes;”;
conn.Open();
// OleDb –Standard Connection
usingSystem.Data.OleDb;
OleDbConnectionconn = new OleDbConnection();
conn.ConnectionString=
“Driver=SQLOLEDB;” +
“DataSource=ServerName;” +
“InitialCatalog=DataBaseName;” +
“User id=UserName;” +
“Password=Secret;”;
conn.Open();
// OleDb –Trusted Connection
usingSystem.Data.OleDb;
OleDbConnectionconn = new OleDbConnection();
conn.ConnectionString=
“Driver=SQLOLEDB;” +
“DataSource=ServerName;” +
“InitialCatalog=DataBaseName;” +
“IntegratedSecurity=SSPI;”;
conn.Open();
// OleDb –via IP Address
usingSystem.Data.OleDb;
OleDbConnectionconn = new OleDbConnection();
conn.ConnectionString=
“Driver=SQLOLEDB;” +
“NetworkLibrary=DBMSSOCN;” +
“DataSource=xxx.xxx.xxx.xxx,1433;” +
“InitialCatalog=DataBaseName;” +
“User id=UserName;” +
“Password=Secret;”;
conn.Open();
Microsoft Sql Express
// .NET DataProvider — Default Relative Path
// StandardConnection
usingSystem.Data.SqlClient;
SqlConnectionconn = new SqlConnection();
conn.ConnectionString=
“Data Source=.\SQLExpress;” +
“User Instance=true;” +
“User Id=UserName;” +
“Password=Secret;” +
“AttachDbFilename=|DataDirectory|DataBaseName.mdf;”
conn.Open();
// .NET DataProvider — Default Relative Path
// TrustedConnection
usingSystem.Data.SqlClient;
SqlConnectionconn = new SqlConnection();
conn.ConnectionString=
“Data Source=.\SQLExpress;” +
“User Instance=true;” +
“Integrated Security=true;” +
“AttachDbFilename=|DataDirectory|DataBaseName.mdf;”
conn.Open();
// .NET DataProvider — Custom Relative Path
// StandardConnection
usingSystem.Data.SqlClient;
AppDomain.CurrentDomain.SetData(
“DataDirectory”,”C:\MyPath\”);
SqlConnectionconn = new SqlConnection();
conn.ConnectionString=
“Data Source=.\SQLExpress;” +
“User Instance=true;” +
“User Id=UserName;” +
“Password=Secret;” +
“AttachDbFilename=|DataDirectory|DataBaseName.mdf;”
conn.Open();
// .NET DataProvider — Custom Relative Path
// TrustedConnection
usingSystem.Data.SqlClient;
AppDomain.CurrentDomain.SetData(
“DataDirectory”,”C:\MyPath\”);
SqlConnectionconn = new SqlConnection();
conn.ConnectionString=
“Data Source=.\SQLExpress;” +
“User Instance=true;” +
“Integrated Security=true;” +
“AttachDbFilename=|DataDirectory|DataBaseName.mdf;”
conn.Open();