An identity field can not be set using insert. It will be auto-incremented by sql. If you want to intially set the values because you need to seed the table with pre-existing values, remove identity, insert values, then turn back on. On an on-going basis, if you want to control the values in the identity column, you will not want to have the field as an identity column at all. sqlbulkcopy does have an keepidentity option. http://msdn.microsoft.com/en-us/library/tchktcdk(VS.80).aspx[^] For performance reasons, I would handle the identity outside of the sqlbulkcopy process as well as other contraints and indexes. Depends on what, how often, how much...
modified on Thursday, March 25, 2010 9:27 AM