Skip to content

Instantly share code, notes, and snippets.

@robfe
Created March 5, 2014 22:38
Show Gist options
  • Save robfe/9378166 to your computer and use it in GitHub Desktop.
Save robfe/9378166 to your computer and use it in GitHub Desktop.
EF Datacontext.WaitForMicroOutageToPass (for sql on azure)
void WaitForMicroOutageToPass() //call this from your constructor
{
if (!Database.Exists())
{
return;
}
var connection = Database.Connection;
for (int i = 0; i < 10; i++)
{
try
{
((IObjectContextAdapter)this).ObjectContext.Connection.Open();
new SqlCommand("declare @i int", (SqlConnection)connection).ExecuteNonQuery();
return;
}
catch
{
connection.Close();
Thread.Sleep(100);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment