Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing "GO" within a transaction
    text
    copied!<p>I'm building a web app that attempts to install/upgrade the database on App_Start. Part of the installation procedure is to ensure that the database has the asp.net features installed. For this I am using the System.Web.Management.SqlServices object.</p> <p>My intention is to do all the database work within an SQL transaction and if any of it fails, roll back the transaction and leave the database untouched.</p> <p>the SqlServices object has a method "Install" that takes a ConnectionString but not a transaction. So instead I use SqlServices.GenerateApplicationServicesScripts like so:</p> <pre><code>string script = SqlServices.GenerateApplicationServicesScripts(true, SqlFeatures.All, _connection.Database); SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, script, ...); </code></pre> <p>and then I use the SqlHelper from the Enterprise Library.</p> <p>but this throws an Exception with a butt-load of errors, a few are below</p> <pre><code>Incorrect syntax near 'GO'. Incorrect syntax near 'GO'. Incorrect syntax near 'GO'. Incorrect syntax near 'GO'. Incorrect syntax near the keyword 'USE'. Incorrect syntax near the keyword 'CREATE'. Incorrect syntax near 'GO'. The variable name '@cmd' has already been declared. Variable names must be unique within a query batch or stored procedure. </code></pre> <p>I'm presuming it's some issue with using the GO statement within an SQL Transaction.</p> <p>How can I get this generated script to work when executed in this way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload