将本地数据库连接到asp.net C#

问题描述:

打开连接时出现以下错误。我正在开发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

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

有一些步骤,你应该确保你正在做他们的权利:

  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