SQL Server數(shù)據(jù)庫(kù)連接字符串的常用聲明
sql server數(shù)據(jù)庫(kù)連接字符串是sql server數(shù)據(jù)庫(kù)中最重要的字符串之一,下面就將為您介紹sql server數(shù)據(jù)庫(kù)連接字符串中常用的聲明,供您參考。
sql server數(shù)據(jù)庫(kù)連接字符串中常用的聲明有:
服務(wù)器聲明 Data Source、Server和Addr等。
數(shù)據(jù)庫(kù)聲明 Initial Catalog和DataBase等。
集成Windows賬號(hào)的安全性聲明 Integrated Security和Trusted_Connection等。
使用數(shù)據(jù)庫(kù)賬號(hào)的安全性聲明 User ID和Password等。
對(duì)于訪問(wèn)數(shù)據(jù)庫(kù)的賬號(hào)來(lái)說(shuō),通常我們?cè)谝恍﹨⒖假Y料上看到ADO.NET的字符串連接往往有如下寫(xiě)法:
string ConnStr = "server = localhost;
user id = sa; password = xxx; database = northwind";
對(duì)于集成Windows安全性的賬號(hào)來(lái)說(shuō),其sql server數(shù)據(jù)庫(kù)連接字符串寫(xiě)法一般如下:
string ConnStr = "server = localhost;
integrated security = sspi; database = northwind";
或string ConnStr = "server = localhost;
trusted_connection = yes; database = northwind";
使用Windows集成的安全性驗(yàn)證在訪問(wèn)數(shù)據(jù)庫(kù)時(shí)具有很多優(yōu)勢(shì):安全性更高、訪問(wèn)速度更快、減少重新設(shè)計(jì)安全架構(gòu)的工作、可以硬編碼連接字符串等,還是很值得使用的。
【編輯推薦】