Follow-on to an earlier question: Force SET IDENTITY_INSERT to take effect faster from MS Access
I'm in the process of upsizing from an MS Access backend to a SQL Server backend. Many of the tables have autonumber primary keys. I'm trying to populate them as follows (pseudocode):
ExecutePassThru "SET IDENTITY_INSERT dbo.Accounts ON"
db.Execute "INSERT INTO sql_Accounts SELECT * FROM mdb_Accounts"
ExecutePassThru "SET IDENTITY_INSERT dbo.Accounts OFF"
In the above code, sql_Accounts
is a linked table connected to the Accounts table in SQL Server and mdb_Accounts
is a linked table connected to the Accounts table in the mdb. This fails with the error,
Cannot insert explicit value for identity column in table 'Accounts' when IDENTITY_INSERT is set to OFF.
I fired up SQL Server Profiler to try to figure out the problem and the issue is that each line of code in my sample may or may not use a different Server Process ID (SPID). In other words, they are using different connections to the backend.
Is there some way to ensure they all use the same connection?