MSSQL错误'底层提供程序在Open上失败“ [英] MSSQL Error 'The underlying provider failed on Open'

查看:448
本文介绍了MSSQL错误'底层提供程序在Open上失败“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .mdf 连接到数据库 entityClient 。现在我想更改连接字符串,以便不会有 .mdf 文件。

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.

以下 connectionString 正确?

<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" />

因为我总是收到错误:


底层提供程序在Open上失败

The underlying provider failed on Open


推荐答案

我有这个错误,并找到了一些解决方案:

I had this error and found a few solutions:

查看你的连接字符串,看起来很有效。我发现这篇博文,这里的问题他们使用的是集成安全性 。如果您在IIS上运行,则您的IIS用户需要访问数据库。

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.

如果您使用实体框架 与事务,实体框架自动打开和关闭与每个数据库调用的连接。因此,当使用事务时,您尝试通过多个连接传播事务。这可以升级到 MSDTC

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.

有关详细信息,请参阅此参考。

将我的代码修改为以下修正:

Changing my code to the following fixed it:

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

这篇关于MSSQL错误'底层提供程序在Open上失败“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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