EF v 6.3.1底层提供程序无法打开 [英] EF v 6.3.1 The underlying Provider failed to open

查看:115
本文介绍了EF v 6.3.1底层提供程序无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AWS的Windows 2012 R2服务器上的IIS中有三个MVC Web应用程序。全部使用Entity framework v 6.3.1  (通过三个不同的Context对象)连接到公共AWS RDS实例上的三个MS SQL Server数据库。由于[win32Exception(0x80004005)],每2-3天应用程序
服务器必须重新启动:找不到网络路径。堆栈跟踪还显示:在using语句中创建新上下文时,基础提供程序无法打开。跟踪日志的快速
扫描显示以下警告:


在应用程序日志中:

异常消息:与网络相关或特定于实例的建立与SQL Server的连接时发生错误。服务器未找到或无法访问。


无法执行套接字上的操作,因为系统缺少足够的缓冲区空间或者队列已满;  在System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)


在系统日志中:

TCP / IP无法建立传出连接,因为最近使用所选本地端点连接到同一个远程端点


由于所有此类端口都在使用,因此从全局TCP端口空间分配临时端口号的请求失败。


当服务崩溃时,仍然可以进入该框。但是,尝试在服务器的命令窗口中使用telnet手动连接到数据库失败。并且只有当服务将
重新开始工作时运行命令iisreset才会开始工作。


看来有什么东西导致操作系统TCP / IP资源耗尽或锁定查看似乎涉及的服务:在上下文的构造函数中有一行代码来加载提供者dll。这可能是锁定/耗尽资源吗?还是有其他原因吗?例如,将三个连接字符串连接到
相同的端点(虽然转到不同的DB)太多了?


public class MyContext:DbContext

    {

        private volatile System.Data.Entity.SqlServer.SqlProviderServices _instance;

        public MyContext():base(" MyContext"){}

        public MyContext(string connName):base(connName)


        {

            //这没有任何作用,是从UI获取dll的工作方式

            //没有它我们会收到EF错误。

            _instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

        } b $ b ...


任何帮助表示赞赏。

解决方案

Hi wellmexico,


当您的应用程序没有足够的权限访问数据库时,Sql Server会触发此错误。请按照以下说明检查它是否适合您。



  1. 尝试使用management studio从服务器连接sql server。如果使用Windows身份验证连接sql server,则将应用程序池标识设置为服务器管理员。 



  2. 如果使用sql server身份验证,请检查Web应用程序的web.config中的连接字符串并设置用户ID和sql server的密码,允许您登录。



  3. 如果您的数据库在其他服务器(访问远程数据库)然后首先启用sql server远程访问sql server属性从sql server management studio启用TCP / IP表单sql server配置管理器。



  4. 执行完所有这些操作后仍然无法访问数据库然后检查服务器表单的防火墙访问数据库并在防火墙中添加一个规则以启用sql server的端口(默认sql server使用1433,检查
    sql server的端口,你需要检查sql server配置管理器网络协议的TCP / IP端口)。



  5. 如果您的sql server在命名实例上运行,那么您需要使用sql serer名称编写端口号,例如117.312。 21.21 / nameofsqlserver,1433。



  6. 如果您使用像amazon aws或microsoft azure这样的云托管,那么服务器或实例将在云防火墙后运行如果您具有用于命名实例的sql server的默认实例或特定端口,则需要在云防火墙中启用1433端口。



  7. 如果您使用的是亚马逊RDS或SQL azure,那么您需要从该实例的安全组启用端口。



  8. 如果您通过sql server身份验证模式访问sql server,请确保启用了"SQL Server和Windows身份验证模式"。 sql server实例属性。


  9.  在对属性进行任何更改后重新启动sql server实例,因为某些更改将需要重新启动。


最好的问候,


Cole Wu


I have three MVC web applications in IIS on a windows 2012 R2 server in AWS. All use Entity framework v 6.3.1  (via three different Context object) to connect to three MS SQL Server databases on a common AWS RDS instance. Every 2-3 days the application server has to be rebooted due to [win32Exception (0x80004005)] : The network path was not found. The stack trace also revealed : The underlying provider failed to open occurring at the point when a new context was being created in a using statement. A quick scan of the trace logs shows the following warnings :

In Application logs:
Exception message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

In System logs:
TCP/IP failed to establish an outgoing connection because the selected local endpoint was recently used to connect to the same remote endpoint

A request to allocate an ephemeral port number from the global TCP port space has failed due to all such ports being in use.

When the services crash it is still possible to get onto the box. However, trying to connect to the databases manually using telnet in a command window from the server fails. And will only start working if the command iisreset is run when the services will start working again.

It appears that something is causing an OS TCP/IP resource to exhaust or lock up.

Looking at the service which seems to be involved: there is a line of code in the constructor of the context to load the provider dll. Could this be locking/exhasting resources? Or is there another reason? For example, having three connections strings to the same endpoint (albeit going to different DBs) is too much?

public class MyContext : DbContext
    {
        private volatile System.Data.Entity.SqlServer.SqlProviderServices _instance;
        public MyContext() : base("MyContext") { }
        public MyContext(string connName) : base(connName)
        {
            // This does nothing and is a work around to get dll loaded from UI
            // without it we get an EF error.
            _instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
        }
...

Any help appreciated.

解决方案

Hi wellmexico,

Sql Server fire this error when your application don't have enough rights to access the database. please follow the following instruction and check if it works for you.

  1. Try to connect sql server from your server using management studio . if you use windows authentication to connect sql server then set your application pool identity to server administrator . 

  2. if you use sql server authentication then check you connection string in web.config of your web application and set user id and password of sql server which allows you to log in .

  3. if your database in other server(access remote database) then first of enable remote access of sql server form sql server property from sql server management studio and enable TCP/IP form sql server configuration manager .

  4. after doing all these stuff and you still can't access the database then check firewall of server form where you are trying to access the database and add one rule in firewall to enable port of sql server(by default sql server use 1433 , to check port of sql server you need to check sql server configuration manager network protocol TCP/IP port).

  5. if your sql server is running on named instance then you need to write port number with sql serer name for example 117.312.21.21/nameofsqlserver,1433.

  6. If you are using cloud hosting like amazon aws or microsoft azure then server or instance will running behind cloud firewall so you need to enable 1433 port in cloud firewall if you have default instance or specific port for sql server for named instance.

  7. If you are using amazon RDS or SQL azure then you need to enable port from security group of that instance.

  8. If you are accessing sql server through sql server authentication mode them make sure you enabled "SQL Server and Windows Authentication Mode" sql server instance property.

  9.   Restart your sql server instance after making any changes in property as some changes will require restart.

Best regards,

Cole Wu


这篇关于EF v 6.3.1底层提供程序无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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