简体   繁体   English

不是Azure的远程数据库上的ReliableDbProvider连接

[英]ReliableDbProvider connections on remote database that is not Azure

I have software that uses ADO.NET to interact with a SQL Server database. 我有使用ADO.NET与SQL Server数据库进行交互的软件。 I want to use the DbProviderFactories to get a factory to get a connection, to be less coupled to the database. 我想使用DbProviderFactories来获得工厂以建立连接,以减少与数据库的耦合。

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. 我的SQL Server是远程的,是到数据中心的不稳定的VPN连接。 It is not an Azure server. 它不是Azure服务器。 I do experience transient faults. 我确实遇到短暂故障。 I would like to use the EnterpriseLibrary.TransientFaultHandling to help manage transient faults. 我想使用EnterpriseLibrary.TransientFaultHandling帮助管理瞬态故障。 I have not been successful finding a DbProviderFactory that I can put in the system.data/DbProviderFactories in my .config. 我没有成功找到可以放入.config中的system.data/DbProviderFactories的DbProviderFactory。

I tried the ReliableDbProvider NuGet. 我尝试了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. 安装软件包之后,我按照示例在工厂中添加ReliableDbProvider.SqlAzure提供程序,然后更改我的连接字符串以使用它。

<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. 我希望我可以假设驱动程序名称中的“ Azure”一词并不是真的意味着它特定于Azure,而是可以用于任何SQL Server连接。 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. 当我在连接字符串中使用providerName ='ReliableDbProvider.SqlAzure'时,会立即收到信号量超时异常。 When I revert to providerName='System.Data.SqlClient' the system operates as expected, until I get a transient transport exception. 当我恢复到providerName ='System.Data.SqlClient'时,系统将按预期运行,直到出现瞬时传输异常。 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? 我是否错过了一些简单的东西,让我可以使用ReliableDbProvider,还是我必须实现一些更复杂的东西来处理瞬态故障并仍然使用DbProviderFactories?

I was making this too complicated. 我让这太复杂了。 I read the Entlib6 manual. 我阅读了Entlib6手册。 The library provides a ReliableSqlConnection class. 该库提供了一个ReliableSqlConnection类。 I can use the Connection member anywhere I need a IDbConnection. 我可以在需要IDbConnection的任何地方使用Connection成员。 I can bind the ReliableSqlConnection.Connection to IDbConnection in my Dependency Injection Container. 我可以在依赖注入容器中将ReliableSqlConnection.Connection绑定到IDbConnection。 I don't really need a ReliableDbProvider to help. 我真的不需要ReliableDbProvider来提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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