關於SQL串連語句中的Integrated Security=SSPI/ture/false

來源:互聯網
上載者:User

關於SQL串連語句中的Integrated Security=SSPI/ture/false

解決方案:
即:Security Support Provider Interface
設定Integrated Security為 True 的時候,串連語句前面的 UserID, PW 是不起作用的,即採用windows身分識別驗證模式。
只有設定為 False 或省略該項的時候,才按照 UserID, PW 來串連。
Integrated Security 可以設定為: True, false, yes, no ,這四個的意思很明白了,還可以設定為:sspi ,相當於 True,建議用這個代替 True。

initial catalog與database的區別是什麼
        Initial Catalog:
DataBase:
兩者沒有任何區別只是名稱不一樣,就好像是人類的真實姓名與曾用名一樣。。都可以叫你。

********************************************

Integrated Security=SSPI 這個表示以當前WINDOWS系統使用者身去登入SQL SERVER伺服器,如果SQL SERVER伺服器不支援這種方式登入時,就會出錯。
你可以使用SQL SERVER的使用者名稱和密碼進行登入,如:
"Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=資料庫名;Data Source=192.168.0.1;User ID=sa;Password=密碼"


***************************************************

Integrated  Security    -  或  -    Trusted_Connection  'false'  當為  false  時,將在串連中指定使用者  ID  和密碼。當為  true  時,將使用當前的  Windows  帳戶憑據進行身分識別驗證。  可識別的值為  true、false、yes、no  以及與  true  等效的  sspi(強烈推薦)。 


*************************************************

ADO.net  中資料庫連接方式
System.Data.SqlClient.SqlConnection
常用的一些連接字串(C#代碼):

SqlConnection  conn  =  new  SqlConnection(  “Server=(local);Integrated  Security=SSPI;database=Pubs“);

SqlConnection  conn  =  new  SqlConnection(“server=(local)\NetSDK;database=pubs;Integrated  Security=SSPI“);

SqlConnection  conn  =  new  SqlConnection(“Data  Source=localhost;Integrated  Security=SSPI;Initial  Catalog=Northwind;“);

SqlConnection  conn  =  new  SqlConnection(“  data  source=(local);initial  catalog=xr;integrated  security=SSPI;
persist  security  info=False;workstation  id=XURUI;packet  size=4096;  “);

SqlConnection  myConn    =  new  System.Data.SqlClient.SqlConnection(“Persist  Security  Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer“);

SqlConnection  conn  =  new  SqlConnection(  “  uid=sa;pwd=passwords;initial  catalog=pubs;data  source=127.0.0.1;Connect  Timeout=900“);

在與 SQL Server 建立串連時出現與網路相關的或特定於執行個體的錯誤。未找到或無法訪問伺服器。請驗證執行個體名稱是否正確並且 SQL Server 已配置為允許遠端連線。 (provider: 具名管道提供者, error: 40 - 無法開啟到 SQL Server 的串連)

如果你的機器裝了sql2000 那Data Source=.肯定是不行的了
因為執行個體名2000和2005的預設的是一樣的 所以2005的執行個體肯定不能用Data Source=.表示

查看sql2005的執行個體名 將Data Source=.\SQLEXPRESS 中的 SQLEXPRESS用你的新執行個體名替換掉。

 

我裝的是SQL Server 2005 EXPRESS 即VS2008內建的資料庫,所以將Data Source寫為:

Data Source=.\SQLEXPRESS即可.SQL2000之前用的.號不能在2005上使用.

今天還遇到一個問題,就是SQL 2005 EXPRESS 啟用SA帳號的問題.搞了半天不能用,儘管已經將SA啟用,但是依然登陸不上,後來,將身分識別驗證設定為SQL+Windows驗證模式,才能在SQL Server Management Studio Express上登入.

VS2008其實已經內建了資料庫,以及資料庫驅動了,平時的開發調試完全可以用這個玩.只是沒有資料庫管理工具,所以無法建表,其實微軟提供了免費的管理工具:

安裝微軟的SQL Server Management Studio Express就可以操作資料庫了.

下載

啟用SA方法如下,開啟MSE,用windows驗證登陸,

 

 

這樣就能用SA來登入啦,當然可以自己修改密碼.

資料庫一開啟,.NET能夠連上資料庫,進行正常的資料存取,那麼之後的開發就容易多啦.

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.