连接SQL Server文件集锦
在新建SqlConnection對象,連接資料庫時連接失敗,出現“常規網絡錯誤。請檢查您的網絡文檔。”
DataSource直接寫IP的話,通信協議是按照TCP/IP協議連接的,如果服務器端TCP/IP服務沒有開啟,則會報錯“不允許遠程連接”
An error has occurred while establishing a connection to the server.? When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
DataSource 不能寫出local 或者127.0.0.1 直接寫電腦名字,這個和SQL 服務器端配置有關,localhost和127.0.0.1是等價的
SQL Server服務器沒開也會發生不允許遠程連接這個錯誤信息~~~
SQL2005的配置在?? Configuration?? Tools?? 目錄里
<!--
Server=(local);Database=DotNetNuke;Trusted_Connection=True
--Uses?? named?? pipes
Server=localhost;Database=DotNetNuke;Trusted_Connection=True
--Uses?? a?? TCP?? port?? negotiated?? on?? port?? 1434?? udp,?? which?? defaults?? to?? 1433
-->
用戶 'sa' 登錄失敗。原因: 未與信任 SQL Server 連接相關聯
解決辦法如下:1.首先要確認你的sql server 2005 “服務器身份驗證”為 “sql server 和windows 身份驗證模式(s)”如圖:
2.要保證你的sa帳號啟用,默認是禁用的方法如下:
在對象資源管理器點擊服務器名稱 點擊安全性 點擊登錄名 如圖:
這些都設置好了之后,SQL服務器要重啟的,問題即可解決!
連接字符串的兩種方式:
Windows驗證:
Data Source=ITWX-03;Initial Catalog=Chat;Integrated Security=True
Integrated Security這個必須要設為True,默認是false(Login failed for user ''. The user is not associated with a trusted SQL Server connection.)
混合驗證:
Data Source=ITWX-03;Initial Catalog=Chat;User ID=sa;Password=’xxxxxx’
?
Integrated Security(集成安全)/Trusted Connection(受信連接):表示Windows認證是否被用來連接數據庫。它可以被設置成真、偽或者是和真對等的SSPI,其缺省值為偽。
如果Integrated Security=’SSPI’,則會發生下面的錯誤信息,原因是SQL登錄用戶里面沒有域賬號ITWX-03\ASPNET,添加進去就ok了。
SSPI雖然和true是對等的,但有什么區別嗎?暫時不知道。如果設為true則不會有下面的錯誤信息了。
轉載于:https://www.cnblogs.com/zqstc/archive/2010/03/26/1696568.html
總結
以上是生活随笔為你收集整理的连接SQL Server文件集锦的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转载:如何在 SQL Server 中使
- 下一篇: 《死或生:女神假期》追加新女神 “伊莉丝