I used this code to initialize RetryManager from Enterprise Library:
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using Microsoft.Practices.TransientFaultHandling;
...
var manager = EnterpriseLibraryContainer.Current.GetInstance<RetryManager>();
return manager.GetDefaultSqlConnectionRetryPolicy();
Now I updated Enterprise Library NuGet package to the newest version and there is no EnterpriseLibraryContainer anymore.
How can I initialize the RetryManager with the new Enterprise Manager? It must be thread safe because my code is executed on web server.
I resolved it this way:
Remove all old NuGet packages and install only those two:
<package id="EnterpriseLibrary.TransientFaultHandling" version="6.0.1304.0" targetFramework="net45" />
<package id="EnterpriseLibrary.TransientFaultHandling.Data" version="6.0.1304.0" targetFramework="net45" />
Add this code once in application:
var strategy = new FixedInterval("fixed", 10, TimeSpan.FromSeconds(3));
var strategies = new List<RetryStrategy> {strategy};
var manager = new RetryManager(strategies, "fixed");
RetryManager.SetDefault(manager);
Then use new connection class from microsoft:
using (var connection = new ReliableSqlConnection(ConnectionString))
{
connection.Open();
...
command.ExecuteNonQueryWithRetry();
}
I also removed all configuration from Web.Config because it's in my code now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With