Unable to access Azure DB from Azure VM if TransactionScope is used

0

I have .net 4.6.1 desktop application that migrates DB from 'old' version to the 'current' version.

It works perfectly fine when I test it locally. But I need to deploy the DB on Azure SQL Server and then migrate the DB. I wanted to do that from Azure VM but I get the following error:

System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) ---> System.ComponentModel.Win32Exception (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   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()

I tried the same from my local machine, accessing Azure SQL Server with my tool and it succeeded, but when I tried to do the same from Azure VM it failed. I tried with Win10, Win Server 2012 and Win Server 2016 VMs.

After some more attempts, I noticed that the issue was caused by using TransactionScope class.

My code is:

using (TransactionScope ts = new TransactionScope())
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
    connection.Open();
    // some stuff
    }
    ts.Complete();
}

Any ideas?

c#
azure
azure-sql-database
azure-virtual-machine
asked on Stack Overflow Apr 10, 2019 by rraszewski

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0