Entity Framework 5 和 Amazon RDS -“底层提供商在 Open 上失败." [英] Entity Framework 5 and Amazon RDS - "The underlying provider failed on Open."

本文介绍了Entity Framework 5 和 Amazon RDS -“底层提供商在 Open 上失败."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C#/实体框架 Web 应用程序可以针对本地 SQL 2012 数据库正常运行.我将数据库复制到一个新的 RDS 实例,并且可以通过 Visual Studio 和 SQL Server Management Studio 访问该数据库.

I have a C# / Entity Framework web application runs fine against a local SQL 2012 db. I copied the db out to a new RDS instance, and can access the db via Visual Studio and SQL Server Management Studio.

我有一个单元测试,它对用户进行身份验证,然后尝试使用实体框架调用 -- dataContext.SaveChanges() 在表中插入一条记录.

I hav a unit test which authenticates the user and then attempts inserts a record in a table using an Entity Framework call -- dataContext.SaveChanges().

我收到以下错误:

{"The underlying provider failed on Open."}
{"No such host is known"}
{"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: TCP Provider, error: 0 - No such host is known.)"}

我一整天都在网上寻找答案,但到目前为止我发现的任何建议都没有成功:

I've poked around the web for answer all day, and so far no success with any of the suggestions I found:

  • 端口 1433 已打开,我可以通过 Telnet 访问入口点
  • 我的 IP 地址包含在默认安全的 CIDR/IP 范围内组.
  • 一旦我尝试打开连接就会出现错误在数据上下文中.
  • db 服务器配置为接受远程连接.
  • db 服务器配置为使用混合身份验证(Windows 和 SQL Server).

实体框架连接字符串

connectionString = "metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MyAwsEntryPoint;Initial Catalog=MyDb;User ID=MyUser;Password=MyPassword;Persist Security Info=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"

标准数据库连接字符串

connectionString = "Data Source=MyAwsEntryPoint,1433;Initial Catalog=MyDb;User ID=MyUser;Password=MyPassword;Persist Security Info=True;Application Name=MyAppName;"

推荐答案

问题出在连接字符串上.具体来说,我在那里有应用程序名称"和应用程序"属性.一旦我删除了那些,它就起作用了.

The problem was in the connection string. Specifically, I had "Application Name" and "App" properties in there. Once I removed those, it worked.

不好:

<add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyDbServer;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyDb;Password=MyPassword;Application Name=MyDb.API.Models;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

好:

<add name="MyDbEntities" connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyDbServer;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyDb;Password=MyPassword;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

这篇关于Entity Framework 5 和 Amazon RDS -“底层提供商在 Open 上失败."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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