AppVeyor - Wait for database to start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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