欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQLServer 2005數(shù)據(jù)庫連接字符串 連接sql2005必備資料

 更新時間:2010年04月14日 17:21:11   作者:  
現(xiàn)在好多朋友開始用sqlserver 2005了,因為跟sql2000有區(qū)別,所以這里整理了下,需要的朋友可以參考下。
連接字符串中常用的聲明有:

服務(wù)器聲明 Data Source、Server和Addr等。

數(shù)據(jù)庫聲明 Initial Catalog和DataBase等。

集成Windows賬號的安全性聲明 Integrated Security和Trusted_Connection等。

使用數(shù)據(jù)庫賬號的安全性聲明 User ID和Password等。

對于訪問數(shù)據(jù)庫的賬號來說,通常我們在一些參考資料上看到ADO.NET的字符串連接往往有如下寫法:
復(fù)制代碼 代碼如下:


string ConnStr = "server = localhost;
user id = sa; password = xxx; database = northwind";

對于集成Windows安全性的賬號來說,其連接字符串寫法一般如下:

復(fù)制代碼 代碼如下:

string ConnStr = "server = localhost;
integrated security = sspi; database = northwind";
或string ConnStr = "server = localhost;
trusted_connection = yes; database = northwind";

使用Windows集成的安全性驗證在訪問數(shù)據(jù)庫時具有很多優(yōu)勢:安全性更高、訪問速度更快、減少重新設(shè)計安全架構(gòu)的工作、可以硬編碼連接字符串等,還是很值得使用的。





SQL Native Client ODBC Driver

標準安全連接
復(fù)制代碼 代碼如下:
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;


您是否在使用SQL Server 2005 Express? 請在“Server”選項使用連接表達式“主機名稱\SQLEXPRESS”。

受信的連接
復(fù)制代碼 代碼如下:
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;


"Integrated Security=SSPI" 與 "Trusted_Connection=yes" 是相同的。

連接到一個SQL Server實例
指定服務(wù)器實例的表達式和其他SQL Server的連接字符串相同。
Driver={SQL Native Client};Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes;


指定用戶名和密碼
oConn.Properties("Prompt") = adPromptAlways

Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;


使用MARS (multiple active result sets)

Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MARS_Connection=yes;

"MultipleActiveResultSets=true"與MARS_Connection=yes"是相同的。
使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。

驗證網(wǎng)絡(luò)數(shù)據(jù)

Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;


使用附加本地數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

使用附加本地數(shù)據(jù)文件夾中的數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

數(shù)據(jù)庫鏡像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;



SQL Native Client OLE DB Provider

標準連接

Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

您是否在使用SQL Server 2005 Express? 請在“Server”選項使用連接表達式“主機名稱\SQLEXPRESS”。

受信的連接

Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;

"Integrated Security=SSPI"與"Trusted_Connection=yes"相同

連接到SQL Server實例
指定服務(wù)器實例的表達式和其他SQL Server的連接字符串相同。
Provider=SQLNCLI;Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=yes;


使用帳號和密碼
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;


使用MARS (multiple active result sets)

Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MarsConn=yes;

"MultipleActiveResultSets=true"和"MARS_Connection=yes"是相同的。
使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。

驗證網(wǎng)絡(luò)數(shù)據(jù)

Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;


使用附加本地數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

使用附加本地數(shù)據(jù)文件夾中的數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

數(shù)據(jù)庫鏡像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;



SqlConnection (.NET)

標準連接

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

使用serverName\instanceName作為數(shù)據(jù)源可以指定SQL Server實例。
您是否在使用SQL Server 2005 Express? 請在“Server”選項使用連接表達式“主機名稱\SQLEXPRESS”。

Standard Security alternative syntax
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;


受信任的連接

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;


Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;


連接到一個SQL Server的實例
指定服務(wù)器實例的表達式和其他SQL Server的連接字符串相同。
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;


來自WinCE設(shè)備的安全連接
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;

僅能用于CE設(shè)備。

帶有IP地址的連接

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

使用MARS (multiple active result sets)

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;MultipleActiveResultSets=true;

使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。

使用附加本地數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

使用附加本地數(shù)據(jù)文件夾中的數(shù)據(jù)庫文件的方式連接到本地SQL Server Express實例

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

為何要使用Database參數(shù)?如果同名的數(shù)據(jù)庫已經(jīng)被附加,那么SQL Server將不會重新附加。

使用在SQL Server Express實例上的用戶實例
Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

數(shù)據(jù)庫鏡像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;

Asynchronous processing
Server=myServerAddress;Database=myDataBase;Integrated Security=True;Asynchronous Processing=True;

相關(guān)文章

最新評論