title: SQL Server 'Resume Next' Equivalent
body: <p>I'm working on a project in VB.net which takes large text files containing T-SQL and executes them against a local SQL database, but I've hit a problem in regards to error handling.</p>
  
  <p>I'm using the following technologies : </p>
  
  <ul>
  <li>VB.net</li>
  <li>Framework 3.5</li>
  <li>SQL Express 2005</li>
  </ul>
  
  <p>The SQL I'm trying to execute is mostly straight-forwards but my app is completely unaware of the schema or the data contained within.  For example : </p>
  
  <pre><code>UPDATE mytable SET mycol2='data' WHERE mycol1=1
  INSERT INTO mytable (mycol1, mycol2) VALUES (1,'data')
  UPDATE mytable SET mycol2='data' WHERE mycol1=2
  INSERT INTO mytable (mycol1, mycol2) VALUES (1,'data')
  UPDATE mytable SET mycol2='data' WHERE mycol1=3
  </code></pre>
  
  <p>The above is a sample of the sort of thing I'm executing, but these files will contain around 10,000 to 20,000 statements each.</p>
  
  <p>My problem is that when using sqlCommand.ExecuteNonQuery(), I get an exception raised because the second INSERT statement will hit the Primary Key constraint on the table.  </p>
  
  <p>I need to know that this error happened and log it, but also process any subsequent statements.  I've tried wrapping these statements in TRY/CATCH blocks but I can't work out a way to handle the error then continue to process the other statements.  </p>
  
  <p>The Query Analyser seems to behave in this way, but not when using sqlCommand.ExecuteNonQuery().</p>
  
  <p>So is there a T-SQL equivalent of 'Resume Next' or some other way I can do this without introducing massive amounts of string handling on my part?</p>
  
  <p>Any help greatly appreciated.</p>