Data Migration

W

WPedersen

Hello -

I'm trying to migrate data from an Access 2000 database to SQL 2005
Express. Both databases have the same schema.

Most primary keys are Auto Increment fields. I'm having the issue that
even if I set primary key manually in my code, the Auto Increment rules
seem to override this. This is very undesirable, as it would corrupt
the relationships of existing data when I read from Access and Write to SQL.

How can I add rows to the SQL database bypassing the Auto Increment value?
i.e.:
ds_SQL.tblCompany.row(x).item("CompanyID") =
ds_Access.tblCompany.row(x).item("CompanyID")

The data migrates, but the Auto Increment value is used. I'm using
typed datasets, ensured the ReadOnly value is False in the Dataset, and
even tried turning off Auto Increment at the Dataset level.

Thanks - I'm lost....


Wayne P.
 
D

Dave Sexton

Hi Wayne,

If the Sql database column is an Identity column, then you will not be able to suppress the auto-numbering from code. In that case
you can use IDENTITY_INSERT in your insert procedure:

ALTER PROC ImportCompany (int @CompanyID, nvarchar(max) @Name)
AS BEGIN

SET NOCOUNT OFF;
SET IDENTITY_INSERT dbo.Companies ON;

INSERT dbo.Companies SELECT @CompanyID, @Name;

SET IDENTITY_INSERT dbo.Companies OFF;

END
 
D

Dave Sexton

Hi Wayne,

If the Sql database column is an Identity column, then you will not be able to suppress the auto-numbering from code. In that case
you can use IDENTITY_INSERT in your insert procedure:

ALTER PROC ImportCompany (int @CompanyID, nvarchar(max) @Name)
AS BEGIN

SET NOCOUNT OFF;
SET IDENTITY_INSERT dbo.Companies ON;

INSERT dbo.Companies SELECT @CompanyID, @Name;

SET IDENTITY_INSERT dbo.Companies OFF;

END
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top