- Local time
- Today, 02:51
- Joined
- Sep 12, 2006
- Messages
- 15,641
I want to upsize data from an access database to a SQL Sever database, using code in an access database. (Note that I prefer to do this in code, although I also tried using the SQL Migration wizard, and had this same problem)
The problem comes with tables with autonumbers.
When I try to do this, it fails on tables with autonumber
insert * into sqltable select accesstable.* from accesstable
so, I try to set the identity insert flag
SET IDENTITY_INSERT sqltable ON
insert * into sqltable select accesstable.* from accesstable
SET IDENTITY_INSERT sqltable OFF
The problem is that the off statement does not work immediately. I have to close the database, and reopen, and then I can process the next table. Any ideas how I can fix this, please.
I think I have tried to solve this before unsuccessfully, but this perhaps explains the problem more clearly.
not sure if this makes a difference, but I am using a dsnless connection string for the .connect property that looks like this.
dsnless = "ODBC;DRIVER={SQL Server};Trusted_Connection=Yes;Server={INSTANCE\SQLEXPRESS};DATABASE=SQLDatabase"
[edit]
this link gave me some help.
http://sqlmag.com/database-administration/15-steps-convert-access-data-sql-server
I think maybe you need two connections - one to set the identity insert, and another to clear it - but I am not sure how to arrange that.
The problem comes with tables with autonumbers.
When I try to do this, it fails on tables with autonumber
insert * into sqltable select accesstable.* from accesstable
so, I try to set the identity insert flag
SET IDENTITY_INSERT sqltable ON
insert * into sqltable select accesstable.* from accesstable
SET IDENTITY_INSERT sqltable OFF
The problem is that the off statement does not work immediately. I have to close the database, and reopen, and then I can process the next table. Any ideas how I can fix this, please.
I think I have tried to solve this before unsuccessfully, but this perhaps explains the problem more clearly.
not sure if this makes a difference, but I am using a dsnless connection string for the .connect property that looks like this.
dsnless = "ODBC;DRIVER={SQL Server};Trusted_Connection=Yes;Server={INSTANCE\SQLEXPRESS};DATABASE=SQLDatabase"
[edit]
this link gave me some help.
http://sqlmag.com/database-administration/15-steps-convert-access-data-sql-server
I think maybe you need two connections - one to set the identity insert, and another to clear it - but I am not sure how to arrange that.
Last edited: