2011-03-25 24 views
0

我有这个问题,当我启动我的网站,并尝试访问我的数据库:asp.net问题,当我访问我的数据库

Oops. The error: 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)

我有一个数据库,我连接到它(第一部分我使用的代码是):

System.Data.SqlClient.SqlConnection con; 
      con = new System.Data.SqlClient.SqlConnection(); 
      con.ConnectionString = "Data Source=.\\SQLEXPRESS; AttachDbFilename=C:\\inetpub\\poject\\App_Data\\data.mdf; Integrated Security = true; Connect Timeout = 30; User Instance = True"; 

任何帮助将不胜感激?

回答

0

路径是否正确?你拼错了“项目”吗?

+0

我没有使用AttachDbFilename连接到数据库,所以我我真的只是猜测在这里。 – 2011-03-25 02:29:14

+0

@Mickey不,你说得对。他不应该得到这个信息,如果这是他的代码,这将有助于“项目”拼写正确。 – Pete 2011-03-25 02:30:30

+0

我知道“项目”拼写错误,但这是我拼写在我的道路上。是他们的任何其他方式连接到数据库,因为这种方式nt工作? – hhh 2011-03-25 02:45:40

0

我如何确保我没有任何语法错误是打开服务器浏览器并连接到我的SQL Server的方式。然后,当我点击服务器资源管理器中“数据连接”下的特定连接时,会出现与每个连接关联的连接字符串属性。我只是复制并粘贴,以避免任何错误。

0

请按照此步骤操作。

  1. 请确保您有SQL管理Studio Express的:Sql management studio express 2008
  2. 附加数据库Data.mdf
  3. 然后改变你的web.config文件中的连接字符串这一点。数据源= \ SQLEXPRESS;初始目录=数据;集成安全性= TRUE;连接超时= 30;用户实例=真

问候