2012-07-22 47 views
0

打開連接時出現以下錯誤。我正在開發Windows應用程序。將本地數據庫連接到asp.net C#

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

請你告訴我如何連接到Microsoft SQL Server Compact 3.5(.NET Framework)。我有VS 2008

+0

你已經解決了這個查詢..? – 2013-03-20 13:02:00

回答

0
string connectionString = @"Data Source=PATH/TO/SDF"; 
SqlCeConnection con = new SqlCeConnection(connectionString); 
string command1 = "sql goes here" 
con.Open(); 
SqlCeCommand sqlcom1 = new SqlCeCommand(command1, con); 
SqlCeDataReader reader = sqlcom1.ExecuteReader(); 
+0

仍然有同樣的錯誤。 SqlCommand和SqlCeCommand有什麼區別 – 2012-07-25 17:14:52

0

有一些步驟,你應該確保你正在做他們的權利:

  1. Make sure your server name is correct, e.g., no typo on the name.
  2. Make sure your instance name is correct and there is actually such an instance on your target machine. [Update: Some application converts \ to . If you are not sure about your application, please try both Server\Instance and Server\Instance in your connection string]
  3. Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true).
  4. Make sure SQL Browser service is running on the server.
  5. If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

來源:http://goo.gl/MZJx

而且也相信這個教程是一個很好的開始通過簡單易行的方式識別錯誤:

鏈接:http://goo.gl/3unpa