معرفی روش های اتصال به دیتابیس SQL Server
1- استفاده از تکنیک ODBC
// اتصال استاندارد با ODBC
using System.Data.Odbc;
//******************
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Uid=UserName; Pwd=Secret";
conn.Open();
-------------------------------------------------------------------------
// اتصال مطمئن با ODBC
using System.Data.Odbc;
//******************
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Uid=admin; Pwd=password";
conn.Open();
// یا
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Trusted_Connection=Yes;";
conn.Open();
2- استفاده از OLEDB
// اتصال استاندارد با OLEDB
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
using System.Data.OleDb;
//******************
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Driver=SQLOLEDB; Data Source=ServerName; Initial Catalog=DataBaseName; Integrated Security=SSPI;";
conn.Open();
3- استفاده از .Net DataProvider
// اتصال استاندارد با .Net DataProvider
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
using System.Data.SqlClient;
//******************
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=ServerName; Initial Catalog=DataBaseName; Integrated Security=SSPI;";
conn.Open();
کوتاه مفید موثر مرسی