2013-11-15 48 views
0

我想學習連接到SQL Server數據庫並使用C#(ASP.NET網站外)執行功能。當我嘗試運行時如何連接到VS Express中的SQL Server數據庫的網絡

SqlConnection con = new SqlConnection("Data Source=.; database=fengshuidb; integrated security = SSPI"); 
SqlCommand cmd = new SqlCommand("Select * from emails", con); 
con.Open(); 

連接我得到以下錯誤與con.Open()指令。

從VS:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

什麼我需要做的配置連接到數據庫?我需要什麼安全設置?這個話題有沒有好的資源?

回答

0

嘗試使用SqlConnectionStringBuilder創建一個有效的連接字符串

0

你錯過了你的連接部分初始目錄。

它改成這樣:

Data Source=Your sql connection ;Initial Catalog=Your Database name;Integrated Security=True 
相關問題