而与SQL Server建立连接时出现与网络相关的或特定于实例的错误。错误定位服务器/实例指定) [英] A network-related or instance-specific error occurred while establishing a connection to SQL Server. Error Locating Server/Instance Specified)

查看:368
本文介绍了而与SQL Server建立连接时出现与网络相关的或特定于实例的错误。错误定位服务器/实例指定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从测试环境移动网络项目,只要取得的tehre开到SQL Server的连接企图这个错误发生在Web服务器。

我们可以插入和读取从SQL Server Management Studio中的数据。

我们怀疑是从坏的连接字符串或从SQL Server使用集成安全性产生的错误,但一直没能证实这一点。

连接字符串。

 <&是connectionStrings GT;
<添加名称=DSVUShort的connectionString =数据源=本地主机\\ SQLEX $ P $干燥综合征;数据库= NS_Survey;集成安全=真; multipleactiveresultsets = TRUE;应用=的EntityFramework/>
< /&是connectionStrings GT;

,其中它被用来

  SqlConnection的连接=新的SqlConnection(ConfigurationManager.ConnectionStrings [DSVUShort]的ToString());
Connection.Open()//弹出错误


解决方案

导致此错误是在ConnectionString中webConfig结果
在webConfig设置的ConnectionString。结果
在webConfig connectionStrin名称和code后面必须相同。

在web.config中:

 <结构>
<&是connectionStrings GT;
    <添加名称=DSVUShort的connectionString =数据源= \\ SQLEX $ P $干燥综合征; AttachDbFilename = | DataDirectory目录| \\ Database.mdf;集成安全=真;用户实例=真的providerName =System.Data.SqlClient的/>
< /&是connectionStrings GT;
<&的System.Web GT;
    <编译调试=真targetFramework =4.0/>
< /system.web>

在code:

  SqlConnection的连接=新的SqlConnection(ConfigurationManager.ConnectionStrings [DSVUShort]的ToString());
Connection.Open();

Moving a web project from test enviroment to the web server made this error occur whenever tehre's an attempt to open a connection to the sql server.

We can insert and read data from sql server management studio.

We're suspecting that the error is created from a bad connection string or from the sql server using integrated security, but haven't been able to confirm that.

the connection string.

<connectionStrings>
<add name="DSVUShort" connectionString="data source=localhost\SQLEXPRESS;database=NS_Survey; integrated security=true;multipleactiveresultsets=True;App=EntityFramework" />
</connectionStrings>

where it is used

SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DSVUShort"].ToString());
Connection.Open() // pops the error

解决方案

causes this error is connectionString in webConfig
Set connectionString in webConfig.
name of connectionStrin in webConfig and code behind must be same.

in web.config:

<configuration>
<connectionStrings>
    <add name="DSVUShort" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
    <compilation debug="true" targetFramework="4.0"/>
</system.web>

in code:

SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DSVUShort"].ToString());  
Connection.Open();

这篇关于而与SQL Server建立连接时出现与网络相关的或特定于实例的错误。错误定位服务器/实例指定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆