sqlServer數據庫常用連接字符串
sqlServer 數據庫常用連接字符串
用戶名和密碼驗證的方式去連接到數據庫服務器
<add name="conStr" connectionString="Data Source=服務器名;Initial Catalog=數據庫名; User Id=用戶名;Password=密碼"/>
<add name="conStr" connectionString="Server=服務器名;Database=數據庫名;User Id=用戶名;Password=密碼"/>
<add name="conStr" connectionString="server=l服務器名;database=數據庫名;uid=用戶名;pwd=密碼;pooling=true;min pool size=1;max pool size=2;connection reset=true"/>
Windows驗證的方式去連接到數據庫服務器
<add name="conStr" connectionString="Data Source=服務器名;Initial Catalog=數據庫名;Integrated Security=True;" />
<add name="conStr" connectionString="Data Source=服務器名;Initial Catalog=數據庫名;Integrated Security=SSPI;" />
<add name="conStr" connectionString="Data Source=服務器名;Initial Catalog=數據庫名;Trusted_Connection = False;Encrypt = yes" />
<add name="conStr" connectionString=" data source=服務器名;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"/>
常用的屬性:
服務器
Data Source
Server
數據庫
Initial Catalog
database
用戶名
User Id
uid
密碼
Password
pwd
啟用連接池
pooling=true(默認值)
最小連接數量
min pool size=1;
最大連接數量
max pool size=2
重置連接池
connection reset=true
身份驗證方式
Integrated Security
當為false時,將在連接中指定用戶ID和密碼。
當為true時,將使用當前的Windows帳戶憑據進行身份驗證。
可識別的值為true、false、yes、no以及與true等效的sspi。
信任連接
1)web.config中Trusted_Connection=true改為Trusted_Connection=false可以消除如下錯誤:
"用戶
'NT AUTHORITY\NETWORK SERVICE' 登錄失敗。"
(2)Trusted_Connection
當為 false 時,將在連接中指定用戶 ID 和密碼。當為 true 時,將使用當前的 Windows 帳戶憑據進行身份驗證。
可識別的值為 true、false、yes、no 以及與 true 等效的 sspi(強烈推薦)。
(3)當在WEB.CONFIG使用Trusted_Connection=true時,SERVER DATABASE已設置為用信任連接了.
加密
Encrypt = yes