title: Executing scripts on databases in the same server concurrently using SMO and Task Parallel Library?
body: <p>I hope my question title is clear enough. What I am trying to do is to concurrently execute update scripts on all Databases in the same Server using SQL Server Management Objects. My current experiment implementation is like this:</p>
  
  <pre><code>var server = new Server(new ServerConnection(new SqlConnection(connString)));
  server.ConnectionContext.InfoMessage += new SqlInfoMessageEventHandler(DBOutputReceived);
  
  var databases = server.Databases.Cast&lt;Database&gt;().ToList();          
  Parallel.ForEach(databases, db =&gt; { db.ExecuteNonQuery(script); });
  </code></pre>
  
  <p>I'm not even sure this is possible using SMO, but this is basically what I want to do. I can see that the ConnectionContext.InfoMessage event will likely have issues, but I'm not sure how to resolve. Should I instead create a separate Server instance for each parallel task? </p>
  
  <p>I would appreciate any advice you can give. </p>
  
  <p>Thanks, Daniel</p>