Skip to content

Instantly share code, notes, and snippets.

@jonathanhickford
Created June 23, 2014 10:29
Show Gist options
  • Save jonathanhickford/1cb0d6665adab8b9c664 to your computer and use it in GitHub Desktop.
Save jonathanhickford/1cb0d6665adab8b9c664 to your computer and use it in GitHub Desktop.
AppVeyor - Wait for database to start
$tries = 5;
$pause = 10; # Seconds to wait between tries
While ($tries -gt 0) {
try {
$ServerConnectionString = "Data Source=(local)\SQL2012SP1;Initial Catalog=master;User Id=sa;PWD=Password12!";
$ServerConnection = new-object system.data.SqlClient.SqlConnection($ServerConnectionString);
$query = "exec sp_configure 'clr enabled', 1;`n"
$query = $query + "RECONFIGURE;`n"
$cmd = new-object system.data.sqlclient.sqlcommand($query, $ServerConnection);
$ServerConnection.Open();
"Running:"
$query
if ($cmd.ExecuteNonQuery() -ne -1) {
"SQL Error";
} else {
"Success"
}
$ServerConnection.Close();
$tries = 0;
}
catch {
"Error:"
$_.Exception.Message
"Retry in $pause seconds. Attempts left: $tries";
Start-Sleep -s $pause;
}
$tries = $tries -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment