title: Wait for creation database to finish
body: <p>I have a code like this:</p>
  
  <pre><code>using (var sqlConnection = new SqlConnection(connectionString))
  {
    sqlConnection.Open();
    using (var sqlCommand = new SqlCommand(scriptText, sqlConnection))
    {
      sqlCommand.ExecuteNonQuery();
    }
  }
  </code></pre>
  
  <p>For the first time I call it to create a DB, then I form a connection string to this DB and try to do some work (<code>Open</code> works fine and says the connection is actually open for this second connection). But I get an "An existing connection was forcibly closed by the remote host" and I can see the sql logs "Could not find database ID 9. Database may not be activated yet or may be in transition". So, actually the <code>ExecuteNonQuery</code> return before the job is done. Sure, I can just spam it until a situation changes, but is there a better way to wait for DB to be ready for work?</p>