【问题标题】:Why is my azure process not connecting to azure database?为什么我的 azure 进程没有连接到 azure 数据库?
【发布时间】:2016-09-29 18:51:39
【问题描述】:

我有一个网络应用和一个批处理池。

在批处理池中,创建的任务使用与 Web 应用相同的数据库。

今天开始批量收到如下异常:

A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)

代码库没有改变,旧版本不起作用,没有更新,它只是突然出现。我在 VS 的受控调试环境中重复了几项任务,它们都通过了,没有抛出任何异常。我进去将批处理节点的IP添加到sql server防火墙规则中,也没有结果。同时,Web 应用程序很好地使用了数据库。

Web 应用程序和批处理池都位于美国东部。

这是我的批处理任务中来自 Program.cs 的 sn-p:

MyEntities db; //MyEntities extends DbContext
System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder connstr = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder();
connstr.ProviderConnectionString = connectionString;
connstr.Provider = "System.Data.SqlClient";
connstr.Metadata = "res://*/MyEntities.csdl|res://*/MyEntities.ssdl|res://*/MyEntities.msl";
try {
    db = new PepeEntities(connstr.ConnectionString);
}

连接字符串如下所示:

Persist Security Info=True; Data Source=<host>; Initial Catalog=<database name>; Integrated Security=False; User ID=<login>; Password=<password>; MultipleActiveResultSets=True; Connect Timeout=30; Encrypt=True;

编辑: 这个问题已经以同样的方式消退了:出乎意料。每当它再次出现时,我都会进行测试。

【问题讨论】:

    标签: c# sql-server entity-framework azure


    【解决方案1】:
    You can try one of these 2 possibilities:
    
    1. Enabling an Execution Strategy:
    
    public class MyEntitiesConfiguration : DbConfiguration 
    { 
        public MyEntitiesConfiguration() 
        { 
            SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy()); 
        } 
    }
    
    # please view more details here:https://msdn.microsoft.com/en-US/data/dn456835
    2. if you have explicitly opened the connection, ensure that you close it. You can use an using statement:
     using(var db = new PepeEntities(connstr.ConnectionString){
    ..do your work
    }
    
    https://blogs.msdn.microsoft.com/appfabriccat/2010/12/10/sql-azure-and-entity-framework-connection-fault-handling/
    

    【讨论】:

    • 好吧,我无法测试其中的任何一个,因为问题会在一段时间后自行停止,但每当这种情况再次发生时,我一定会记住这一点。暂时把这些东西放在架子上。同时,请投赞成票。
    猜你喜欢
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    相关资源
    最近更新 更多