<p>In my <a href="https://stackoverflow.com/questions/222442/sql-server-running-large-script-files">eternal</a> <a href="https://stackoverflow.com/questions/224830/how-do-i-set-a-sql-server-scripts-timeout-from-within-the-script">saga</a> to insert 1.4 million rows of data from a SQL script, I've written a basic WinForms app that takes each line of the script and executes it individually.</p>

<p>However, because the original script contained</p>

<pre><code>SET IDENTITY_INSERT [Table] OFF
</code></pre>

<p>and SET is a session-wide command, this setting is getting lost on every SQL call, meaning that each line is failing.  Is there a way to set IDENTITY_INSERT off for the whole table, database-wide just so I can make these individual calls without them failing?  Or perhaps I can tell it to ignore the identity specification by appending a command to each line?</p>

BULK INSERT
won't work for you?  Or the SQL Server Import/Export Wizard (
here
or
here
)?  I know import/export can turn off identity insert for the whole import.  I'm reasonably certain you can do it just prior to BULK INSERT