实体框架底层提供程序在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.
我已经检查:
- 服务器与电脑之间的连接正常
- 我可以使用用户名testuser登录数据库和密码$ 1234
- 我已经检查了数据库(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:
- 创建一个空白的记事本并将其重命名为X.UDL
- 双击打开它
- 在连接选项卡下选择服务器名称/输入名称
使用正确的凭据和DB - 单击确定保存它。
- Create a blank notepad and rename it to "X.UDL"
- Double click to open it
- Under connections tab choose the server name/enter the name use the correct credentials and DB
- Click OK to save it.
现在在记事本中打开文件,并比较连接字符串属性。
Now open the file in Notepad and compare the connection string properties.