简体   繁体   中英

Why is my azure process not connecting to azure database?

I have a web app and a batch pool.

In the batch pool, created tasks are using the same database as the web app.

Today I started receiving the following exception in the batch:

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

The code base has not changed, older versions do not work, there were no updates, it just popped out of the blue. I repeated a couple tasks in a controlled debug environment in VS and they went through without any exceptions thrown. I went in and added the batch node's IP to the sql server firewall rules, also no result. Meanwhile, the web application uses the database just fine.

Both the web app and batch pool are located in East US.

Here's a snippet from Program.cs in my batch task:

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);
}

The connection string looks like this:

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;

Edit: This problem has subsided the same way it appeared: out of the blue. I'll carry out tests whenever it surfaces again.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM