实体框架底层提供程序在Open上失败 [英] Entity Framework The underlying provider failed on Open

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

问题描述

以下是我的连接字符串:

Below is my connection string:


connectionString =metadata = res:// /EDMX.Test.csdl | res:// /EDMX.Test.ssdl|res://*/EDMX.Test.msl;provider=System.Data.SqlClient;provider
connection string =Data Source = home_computer;初始
Catalog = db_Test; Persist Security Info = True; User
ID = testUser; Password = $ 1234; MultipleActiveResultSets = True

connectionString="metadata=res:///EDMX.Test.csdl|res:///EDMX.Test.ssdl|res://*/EDMX.Test.msl;provider=System.Data.SqlClient;provider connection string="Data Source=home_computer;Initial Catalog=db_Test;Persist Security Info=True;User ID=testUser;Password=$1234;MultipleActiveResultSets=True""

这是程序卡住的代码:

EDMX.TestingEntity context = new EDMX.TestingEntity();

var query = from t in context.User
            where t.UserName == _userName
            select t;

运行上述代码后,我检查变量查询并发现异常

After running the above code, I check the variable query and found an exception


底层提供商打开失败。

The underlying provider failed on Open.

我已经检查:


  1. 服务器与电脑之间的连接正常

  2. 我可以使用用户名testuser登录数据库和密码$ 1234

  3. 我已经检查了数据库(SQL Server)中的安全设置,该权限已授予testUser

为什么会发生这种异常?我正在使用.net 4.5

Why does this exception happen? I'm using .net 4.5

添加:

我再次尝试了一下内部异常,它是:
与SQL Server建立连接时发生与网络相关或实例特定的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供程序:命名管道提供程序,错误:40 - 无法打开到SQL Server的连接)

I tried again, look at the inner exception and it was: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

我知道这可能是一个网络问题,但我已经关闭服务器的防火墙,也是我的电脑,再试一次,但仍然没有成功..

I know it might be a network problem but I've turned off the firewall of server and also my computer and tried again but still not success..

刚刚将connectionstring复制到程序测试这个连接,它运行良好..

Just now Copied the connectionstring to a program to test this connection and it was functioning well..

我只是回滚所有的变化,再次测试, p>

I just rollback all changes and test again and it worked

推荐答案

似乎是一个连接问题。您可以使用数据链接属性来查找连接是否正常。执行以下操作:

Seems like a connection issue. You can use the Data link properties to find if the connection is fine. Do the following:


  1. 创建一个空白的记事本并将其重命名为X.UDL

  2. 双击打开它

  3. 在连接选项卡下选择服务器名称/输入名称
    使用正确的凭据和DB

  4. 单击确定保存它。

  1. Create a blank notepad and rename it to "X.UDL"
  2. Double click to open it
  3. Under connections tab choose the server name/enter the name use the correct credentials and DB
  4. Click OK to save it.

现在在记事本中打开文件,并比较连接字符串属性。

Now open the file in Notepad and compare the connection string properties.

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

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