实体框架5和Amazon RDS - "底层提供程序未能在开放和QUOT;。 [英] Entity Framework 5 and Amazon RDS - "The underlying provider failed on Open."

本文介绍了实体框架5和Amazon RDS - "底层提供程序未能在开放和QUOT;。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#/实体框架的Web应用程序正常运行对本地SQL2012分贝。我复制了DB出一个新的RDS实例,并且可以通过Visual Studio和SQL Server Management Studio中访问数据库。

我甲肝一个单元测试,验证用户身份,然后尝试插入使用实体框架调用表中的一个记录 - dataContext.SaveChanges()

我收到以下错误:

  {基础提供程序未能打开。}
{没有这样的主机被称为}
建立SQL Server的连接{时出现与网络相关的或特定于实例的错误。
服务器找不到或无法访问。验证实例名称是否正确,以及SQL Server配置为允许远程连接。
(provider:TCP提供程序,error:0  - 没有这样的主机是已知的。)}
 

我已经捅了一整天在网上进行答复左右,而到目前为止,还没有任何的发现我的建议成功的:

  • 在1433端口是开放的,我可以通过Telnet访问入口点
  • 在我的IP地址,则适用CIDR / IP范围的默认安全 组。
  • 的错误,当我尝试打开连接时发生 在DataContext的。
  • 在DB服务器被配置为接受远程 连接。
  • 在DB服务器被配置为使用混合身份验证 (包括Windows和SQL Server)。

实体框架的连接字符串

 的connectionString = "metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= MyAwsEntryPoint;初始目录= mydb的;用户ID = MYUSER;密码= MyPassword输入;坚持安全信息= TRUE; MultipleActiveResultSets = TRUE;应用=的EntityFramework和放大器; QUOT;的providerName =System.Data这。 EntityClient
 

标准DB连接字符串

 的connectionString =数据源= MyAwsEntryPoint,1433;初始目录= mydb的;用户ID = MYUSER;密码= MyPassword输入;坚持安全信息= TRUE;应用程序名称= MyAppName;
 

解决方案

但问题是连接字符串研究。具体而言,我有应用程序名,并在那里应用程序的属性。有一次,我删除了这些,它的工作。

坏的:

 <添加名称=MyDbEntities connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= MyDbServer;初始目录= mydb的;持续安全信息= TRUE;用户ID = MYDB;密码= MyPassword输入;应用程序名称= MyDb.API.Models; MultipleActiveResultSets = TRUE;应用=的EntityFramework和放大器; QUOT ;的providerName =System.Data.EntityClient/>
 

GOOD:

 <添加名称=MyDbEntities connectionString="metadata=res://*/MyDb.csdl|res://*/MyDb.ssdl|res://*/MyDb.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= MyDbServer;初始目录= mydb的;持续安全信息= TRUE;用户ID = MYDB;密码= MyPassword输入; MultipleActiveResultSets =真放; QUOT;的providerName =System.Data.EntityClient/&GT ;
 

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.

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().

I get the following error:

{"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:

  • Port 1433 is open I can access the entry point via Telnet
  • My IP address is covered by the CIDR/IP range for the default security group.
  • The error occurs as soon as I attempt to open the connection on the datacontext.
  • The db server is configured to accept remote connections.
  • The db server is configured to use mixed authentication (both Windows and SQL Server).

Entity Framework Connection String

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"

Standard Db Connection String

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.

BAD:

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

GOOD:

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

这篇关于实体框架5和Amazon RDS - &QUOT;底层提供程序未能在开放和QUOT;。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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