我有一个网络应用程序和一个批处理池。
在批处理池中,创建的任务使用与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应用程序使用数据库就好了。
网络应用和批处理池都位于美国东部。
以下是我的批处理任务中Program.cs的一个片段:
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;
编辑: 这个问题已经以同样的方式消退了:出乎意料。我会在它再次出现时进行测试。
答案 0 :(得分: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/