VS2010与数据库的连接
 <configuration>
  <appSettings>
    <add key="ConnectionString" value="Data Source=(local)\SQL2008;Database=LibraryMS;Uid=root;Pwd=root;"/>
  </appSettings>
  <connectionStrings/>
我想问一下我数据库写的这个格式有没有错,程序运行的时候总显示数据库连接那里出错了,要怎么改正呢。谢谢各位大神了

3个回答

连接字符串有字段没配置对。

Helodie_Jaqueline
Helodie_Jaqueline System.Data.SqlClient.SqlException: 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)
5 年多之前 回复
Helodie_Jaqueline
Helodie_Jaqueline 回复oyljerry: 错误信息是这个:System.Data.SqlClient.SqlException: 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)
5 年多之前 回复
oyljerry
oyljerry 回复Helodie_Jaqueline: 错误信息是什么
5 年多之前 回复
Helodie_Jaqueline
Helodie_Jaqueline 不好意思。。。刚刚的代码好像没有显示出来,可以再帮我看一下吗。谢谢了
5 年多之前 回复

"Data Source=服务器名称;Initial Catalog=数据库里项目的名称;User ID=登入数据库的账号;Password=登入数据库的密码";

参考SQL Server connection strings
注意不要把不同的写法糅合到一起

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问