MSSQL错误“的基础提供失败的打开” [英] MSSQL Error 'The underlying provider failed on Open'

查看:244
本文介绍了MSSQL错误“的基础提供失败的打开”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用密度纤维板用于连接到数据库 entityClient 。现在我想更改连接字符串,这样就不会有密度纤维板文件。

是下列的connectionString 是否正确?

 <&是connectionStrings GT;
   <! - <添加名称=conString connectionString=\"metadata=res://*/conString.csdl|res://*/conString.ssdl|res://*/conString.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= \\ SQL2008。AttachDbFilename = | DataDirectory目录| \\ NData.mdf;集成安全性= TRUE;连接超时= 30;用户实例=真; MultipleActiveResultSets =真放; QUOT;的providerName =系统.Data.EntityClient/> - >
   <添加名称=conString connectionString=\"metadata=res://*/conString.csdl|res://*/conString.ssdl|res://*/conString.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= \\ SQL2008;初始目录= n数据;集成安全性= TRUE;连接超时= 30;用户实例=真; MultipleActiveResultSets =真放; QUOT;的providerName =System.Data.EntityClient />

由于我总是得到错误:


  

底层提供程序未能在打开



解决方案

我有这个错误,并发现了几个解决方案:

在连接字符串看,它看起来有效。我发现这个博客帖子,这里的问题是,他们使用<一href=\"http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.integratedsecurity.aspx\">Integrated安全。如果您正在运行在IIS上,您的IIS用户需要访问数据库中。

如果您使用的是实体框架 <一个href=\"http://stackoverflow.com/questions/452129/entity-framework-using-transactions-and-rollbacks-possible\">with交易的,实体框架自动打开和关闭与每个数据库调用的连接。因此,在使用事务时,你正在试图走出与s $ P $垫交易在多个连接。这提升到 MSDTC

有关更多信息,请参见本参考。

更改我的code到下列固定的:

 使用(DatabaseEntities上下文=新DatabaseEntities())
{
    context.Connection.Open();
    // 其余的部分
}

I was using an .mdf for connecting to a database and entityClient. Now I want to change the connection string so that there will be no .mdf file.

Is the following connectionString correct?

<connectionStrings>
   <!--<add name="conString" connectionString="metadata=res://*/conString.csdl|res://*/conString.ssdl|res://*/conString.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQL2008;AttachDbFilename=|DataDirectory|\NData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />-->
   <add name="conString" connectionString="metadata=res://*/conString.csdl|res://*/conString.ssdl|res://*/conString.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQL2008;Initial Catalog=NData;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

Because I always get the error:

The underlying provider failed on Open

解决方案

I had this error and found a few solutions:

Looking at your connection string, it looks valid. I found this blog post, the problem here is that they were using Integrated Security. If you are running on IIS, your IIS user needs access to the database.

If you are using Entity Framework with Transactions, Entity Framework automatically opens and closes a connection with each database call. So when using transactions, you are attempting to spread a transaction out over multiple connections. This elevates to MSDTC.

(See this reference for more information.)

Changing my code to the following fixed it:

using (DatabaseEntities context = new DatabaseEntities())
{
    context.Connection.Open();
    // the rest
}

这篇关于MSSQL错误“的基础提供失败的打开”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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