简体   繁体   中英

ReliableDbProvider connections on remote database that is not Azure

I have software that uses ADO.NET to interact with a SQL Server database. I want to use the DbProviderFactories to get a factory to get a connection, to be less coupled to the database.

ConnectionStringSettings connectionStringEntry = ConfigurationManager.ConnectionStrings["Default"];
string providerName = connectionStringEntry.ProviderName;
DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionStringEntry.ConnectionString;

and so on...

My SQL Server is remote, a shaky VPN connection to a data center. It is not an Azure server. I do experience transient faults. I would like to use the EnterpriseLibrary.TransientFaultHandling to help manage transient faults. I have not been successful finding a DbProviderFactory that I can put in the system.data/DbProviderFactories in my .config.

I tried the ReliableDbProvider NuGet. After installing the package, I followed the example to add the ReliableDbProvider.SqlAzure provider in the Factories, then change my connection string to use it.

<system.data>
  <DbProviderFactories>
    <add name="Reliable Provider"
         invariant="ReliableDbProvider.SqlAzure"
         description="Reliable DB Provider for SQL Server"
         type="ReliableDbProvider.SqlAzure.SqlAzureProvider, ReliableDbProvider"/>
    <add name="Sql Azure Reliable Provider With Timeout Retries"
         invariant="ReliableDbProvider.SqlAzureWithTimeoutRetries"
         description="Reliable Db Provider for SQL Azure with Timeout Retries"
         type="ReliableDbProvider.SqlAzureWithTimeoutRetries.SqlAzureProvider, ReliableDbProvider" />
  </DbProviderFactories>
</system.data>

I hoped I could assume that the word "Azure" in the driver names didn't really mean it was specific to Azure, but would work for any SQL Server connection. I am not convinced I can make that assumption. When I use providerName='ReliableDbProvider.SqlAzure' in the connection string I get an immediate semaphore timeout exception. When I revert to providerName='System.Data.SqlClient' the system operates as expected, until I get a transient transport exception. Am I missing something simple that would allow me to use the ReliableDbProvider, or do I have to implement something more complicated to handle transient faults and still usd the DbProviderFactories?

I was making this too complicated. I read the Entlib6 manual. The library provides a ReliableSqlConnection class. I can use the Connection member anywhere I need a IDbConnection. I can bind the ReliableSqlConnection.Connection to IDbConnection in my Dependency Injection Container. I don't really need a ReliableDbProvider to help.

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