Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It fails because the GO word is not recognized when you pass the full script as a simple string to ExecuteNonQuery. However, the <a href="http://msdn.microsoft.com/en-us/library/ms199328.aspx" rel="nofollow">overload of ExecuteNonQuery</a> that takes a StringCollection object is stated that accepts a script separated by the GO </p> <p>I will try in this way: (Not tested)</p> <pre><code>StringCollection col = new StringCollection(); col.Add(script); server.ConnectionContext.ExecuteNonQuery(col); </code></pre> <p>if this doesn't work then the only workaround that comes to mind is</p> <pre><code>string goSplitter = new string[] { "\r\nGO\r\n" }; string[] cmdParts = script.Split(goSplitter, StringSplitOptions.RemoveEmptyEntries); StringCollection col = new StringCollection(); col.AddRange(cmdParts); server.ConnectionContext.ExecuteNonQuery(col); </code></pre> <p><strong>UPDATE</strong> I have tested a small part of your script agains a database of mine with the code you have provided, and contrary to what is my understanding of the documentation about <a href="http://msdn.microsoft.com/en-us/library/ms199350%28v=sql.100%29.aspx" rel="nofollow">ExecuteNonQuery with a single string</a>, it has worked as expected. So it is possible that you have some syntax error or other problem in the whole script. I suggest to test it inside the Sql Management Studio console</p> <p><strong>UPDATE 2</strong><br> Now I was really curious, so I fired up Reflector to investigate the code of ExecuteNonQuery and now the mistery is solved. These are the first decompiled lines of the method that gets a single string.</p> <pre><code>public int ExecuteNonQuery(string sqlCommand, ExecutionTypes executionType) { int num6; this.CheckDisconnected(); int statementsToReverse = 0; int num2 = 0; StringCollection strings = this.GetStatements(sqlCommand, executionType, ref statementsToReverse); ........ </code></pre> <p>So the single string is passed to an internal method called GetStatements that return a StringCollection </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