Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal .Net Framework Data Provider error 6 in SQL Azure

I regularly experience the above error when creating connections to Azure SQL databases. I've implemented ReliableSqlConnection with retry logic in attempt to avoid this issue but it has been to no avail. Following is an example error stack trace:

System.InvalidOperationException
Internal .Net Framework Data Provider error 6. 
System.InvalidOperationException: Internal .Net Framework Data Provider error 6. 
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ReliableSqlConnection.<Open>b__1()
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0()
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action)
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ReliableSqlConnection.<Open>b__0()
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.<>c__DisplayClass1.<ExecuteAction>b__0()
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy.ExecuteAction(Action action)
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.ReliableSqlConnection.Open(RetryPolicy retryPolicy)

This issue happens when creating a new database in an elastic pool. The SQL command text is execute in the following method:

public void ExecuteCommandText(string commandText)
    {
        if (IsNullOrEmpty(commandText))
            throw new ArgumentNullException(nameof(commandText));

        List<string> commandSteps = SplitCommandText(commandText);

        using (var sqlConnection = CreateConnection())
        {
            foreach (string commandStep in commandSteps)
            {
                using (SqlCommand command = sqlConnection.CreateCommand())
                {
                    command.CommandText = commandStep;
                    command.CommandTimeout = _commandTimeout;
                    command.ExecuteNonQuery();
                    command.Dispose();
                }
            }
        }
    }

Where:

private ReliableSqlConnection CreateConnection()
    {
        if (IsNullOrEmpty(ConnectionString))
            throw new InvalidOperationException("Connection string is not defined.");

        ReliableSqlConnection sqlConnection = new ReliableSqlConnection(ConnectionString, _retryPolicy, _retryPolicy);
        sqlConnection.Open();
        return sqlConnection;
    }

And:

var retryStrategy = new ExponentialBackoff(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(2));
_retryPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy);

The connection string is of the format:

$"Server=tcp:{serverName},1433;Data Source={serverName};Persist Security Info=False;User ID='{user}';Password='{password}';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=90;"

Also, I've checked the eDTU usage on my elastic pool:

Elastic pool eDTU usage

The first spike is from creating 1 database in the pool, the second is for 2, the third is for 3 and the fourth is for creating 4 databases concurrently. The elastic pool service tier is Standard 100.

like image 958
ASH Avatar asked Feb 03 '17 15:02

ASH


People also ask

What is .NET data provider for SQL Server?

The . NET Framework Data Provider for SQL Server (SqlClient) uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer.

Can not connect to Azure SQL Server?

Steps to resolve persistent connectivity issuesSet up firewall rules to allow the client IP address. On all firewalls between the client and the Internet, make sure that port 1433 is open for outbound connections. Review Configure the Windows Firewall to Allow SQL Server Access for additional pointers.

How do I connect Entity Framework to Azure?

Go to your Azure account find New, Data + Storage, then click SQL Databases. Fill the details and proceed to next. After creating SQL Azure database successfully, then just go to Visual Studio and open Server Explorer. Just login with Azure Account and find the database created in Azure.

How do I connect to Azure SQL Server Visual Studio?

Open your project in Visual Studio. In Solution Explorer, right-click the Connected Services node, and, from the context menu, select Add Connected Service. In the Connected Services tab, select the + icon for Service Dependencies. In the Add Dependency page, select Azure SQL Database.


1 Answers

This is one of Azure SQL transient error. A lot of info is here https://msdn.microsoft.com/en-us/library/dn440719(v=pandp.60).aspx. Seem the same error when trying to do backups via code. In those cases I drop and re-initiate.

like image 187
Stefan Georgiev Avatar answered Oct 14 '22 08:10

Stefan Georgiev