Group:  Microsoft Access ยป microsoft.public.access.odbcclientsvr
Thread: Identity_Insert Problem

Identity_Insert Problem
"Lorenz Ingold" <l.ingold[ at ]winvs.ch> 5/30/2007 8:26:52 AM
I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
several tables from an Access DB to an SQL DB. In an mdb-program I link all
the tables, so that I have normal linked tables (the source) and odbc-linked
tables (the target). The tables have an identity, so in a special
ODBC-direct workspace I send the TSQL-statement "SET IDENTITY_INSERT mytable
ON" (which seems to be successful, I checked that), then I execute an INSERT
INTO-query on the linked tables for transferring all the data, then I send
"SET IDENTITY_INSERT mytable OFF". Then comes the next table, and so on.
For the first table everything is OK. The second table however failed when
trying the INSERT INTO-query, giving the error "Cannot insert explicit value
for identity column in table 'mytable2' when IDENTITY_INSERT is set to OFF".
If I change the order of the first two tables, then again the one that
executes first is successful and the one that comes after, failed.
Now I found an article of Microsoft
(http://support.microsoft.com/kb/878501/en-us) that addresses this problem
(not saying, however, that one table might work and the second not).
Microsoft says that the resolution is to install SP4 of the SQL-server 2000.
I did that, but it didn't help at all; there is exactly the same behaviour
as before. What is wrong here, and what should be done?


Re: Identity_Insert Problem
Stefan Hoffmann <stefan.hoffmann[ at ]explido.de> 5/30/2007 8:34:06 AM
hi Lorenz,

Lorenz Ingold wrote:
[Quoted Text]
> What is wrong here, and what should be done?
Go the easy way: use the impotr wizard in the Enterprise Manager (EM).


mfG
--> stefan <--
Re: Identity_Insert Problem
"Lorenz Ingold" <l.ingold[ at ]winvs.ch> 5/30/2007 10:15:21 AM
Thanks; but I need to say something additional: Many of the data cannot be
transferred "one to one". For some data we need to JOIN some tables to build
the data for the target table. Can this be done with the import wizard?

"Stefan Hoffmann" <stefan.hoffmann[ at ]explido.de> wrote in message
news:u%23tiEVpoHHA.716[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> hi Lorenz,
>
> Lorenz Ingold wrote:
>> What is wrong here, and what should be done?
> Go the easy way: use the impotr wizard in the Enterprise Manager (EM).
>
>
> mfG
> --> stefan <--


Re: Identity_Insert Problem
Stefan Hoffmann <stefan.hoffmann[ at ]explido.de> 5/30/2007 11:47:12 AM
hi Lorenz,

Lorenz Ingold wrote:
[Quoted Text]
> Thanks; but I need to say something additional: Many of the data cannot be
> transferred "one to one". For some data we need to JOIN some tables to build
> the data for the target table. Can this be done with the import wizard?
Yes, you can.


mfG
--> stefan <--
Re: Identity_Insert Problem
"Lorenz Ingold" <l.ingold[ at ]winvs.ch> 5/30/2007 2:40:57 PM
I am not very happy with it. We have a tool (implemented in an mdb) that has
a "core" which makes the things I told, and this (very interestingly) works,
i.e. does not have the problem I mentioned. However around this "core" there
are many other steps that are a lot of manual work. The whole thing consists
also on Release checking, checking of data integrity, checking of date
values and much more. My job is to automate the whole thing as much as
possible, so the same tool should do all (with a little bit of user
interaction). The problem I told of only arises after this "widening" of the
already existing core. I can hardly accept that the whole project should
fail only because of this very technical problem, that arises only under
certain circumstances. I thought it could be because in the new project
there are some more opened database-object-variables than in the old
project, but I have had no success in finding out whether this is the cause
or not, the behavior is such "chaotic" and variable from one test to the
next that it seems very that much time is necessary to isolate the exact
cause.


"Stefan Hoffmann" <stefan.hoffmann[ at ]explido.de> wrote in message
news:extq%23AroHHA.4220[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> hi Lorenz,
>
> Lorenz Ingold wrote:
>> Thanks; but I need to say something additional: Many of the data cannot
>> be transferred "one to one". For some data we need to JOIN some tables to
>> build the data for the target table. Can this be done with the import
>> wizard?
> Yes, you can.
>
>
> mfG
> --> stefan <--


Re: Identity_Insert Problem
Stefan Hoffmann <stefan.hoffmann[ at ]explido.de> 5/30/2007 3:00:47 PM
hi Lorenz,

Lorenz Ingold wrote:
[Quoted Text]
> I am not very happy with it.
You may use DTS, which is the right way to import data on a regular
schedule.

> However around this "core" there
> are many other steps that are a lot of manual work. The whole thing consists
> also on Release checking, checking of data integrity, checking of date
> values and much more.
Release checking? Do you like to implement a kind of update? In such an
case create a sql batch to run against your server.


mfG
--> stefan <--
Re: Identity_Insert Problem
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)> 5/30/2007 7:33:33 PM
Did you try closing the first ODBCDirect workspace and reopening a new one?

A second possibility would be to use an intermediate table on SQL-Server
without an identity column and copy first to this table before copying from
it to the real table. The second step can be done entirely on the
SQL-Server, so it should be very fast.

A final possibility is that Access is opening more than a single connection.
I don't remember how exactly the ODBCDirect is working but maybe you will
have some hints if you take a look with the SQL-Server profiler. It could
also be a problem with the Connections Pool, hard to say. With many
providers, you can deactivate the connections pool, so maybe there is
something there to look at.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
news:OTM7HRpoHHA.3952[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
>I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
>several tables from an Access DB to an SQL DB. In an mdb-program I link all
>the tables, so that I have normal linked tables (the source) and
>odbc-linked tables (the target). The tables have an identity, so in a
>special ODBC-direct workspace I send the TSQL-statement "SET
>IDENTITY_INSERT mytable ON" (which seems to be successful, I checked that),
>then I execute an INSERT INTO-query on the linked tables for transferring
>all the data, then I send "SET IDENTITY_INSERT mytable OFF". Then comes the
>next table, and so on.
> For the first table everything is OK. The second table however failed when
> trying the INSERT INTO-query, giving the error "Cannot insert explicit
> value for identity column in table 'mytable2' when IDENTITY_INSERT is set
> to OFF". If I change the order of the first two tables, then again the one
> that executes first is successful and the one that comes after, failed.
> Now I found an article of Microsoft
> (http://support.microsoft.com/kb/878501/en-us) that addresses this problem
> (not saying, however, that one table might work and the second not).
> Microsoft says that the resolution is to install SP4 of the SQL-server
> 2000. I did that, but it didn't help at all; there is exactly the same
> behaviour as before. What is wrong here, and what should be done?
>


Re: Identity_Insert Problem
"Lorenz Ingold" <l.ingold[ at ]winvs.ch> 6/1/2007 6:16:24 AM
[Quoted Text]
> Did you try closing the first ODBCDirect workspace and reopening a new
> one?
Maybe this not, but a lot of other things. Instead of using an ODBCdirect
workspace a used a pass through query, so there is no ODBCdirect workspace.
Or a opened a new (jet) workspace for the bulk query only after setting the
IDENTITY_INSERT. Nothing helped. I then thought about two alternative
technologies, namely (1) constructing a script that imports all the data
(encouraged by a former answer in this newsgroup), and (2) using SQL-DMO. I
guessed to have (in my situation) a little bit less work with SQL-DMO, so I
tried this and it worked. Of course (like it would also be with a script)
the transfer is then done record by record instead with one single query for
a whole table. But at least it works now.

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uNiKQGvoHHA.4400[ at ]TK2MSFTNGP03.phx.gbl...
> Did you try closing the first ODBCDirect workspace and reopening a new
> one?
>
> A second possibility would be to use an intermediate table on SQL-Server
> without an identity column and copy first to this table before copying
> from it to the real table. The second step can be done entirely on the
> SQL-Server, so it should be very fast.
>
> A final possibility is that Access is opening more than a single
> connection. I don't remember how exactly the ODBCDirect is working but
> maybe you will have some hints if you take a look with the SQL-Server
> profiler. It could also be a problem with the Connections Pool, hard to
> say. With many providers, you can deactivate the connections pool, so
> maybe there is something there to look at.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
>
> "Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
> news:OTM7HRpoHHA.3952[ at ]TK2MSFTNGP03.phx.gbl...
>>I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
>>several tables from an Access DB to an SQL DB. In an mdb-program I link
>>all the tables, so that I have normal linked tables (the source) and
>>odbc-linked tables (the target). The tables have an identity, so in a
>>special ODBC-direct workspace I send the TSQL-statement "SET
>>IDENTITY_INSERT mytable ON" (which seems to be successful, I checked
>>that), then I execute an INSERT INTO-query on the linked tables for
>>transferring all the data, then I send "SET IDENTITY_INSERT mytable OFF".
>>Then comes the next table, and so on.
>> For the first table everything is OK. The second table however failed
>> when trying the INSERT INTO-query, giving the error "Cannot insert
>> explicit value for identity column in table 'mytable2' when
>> IDENTITY_INSERT is set to OFF". If I change the order of the first two
>> tables, then again the one that executes first is successful and the one
>> that comes after, failed.
>> Now I found an article of Microsoft
>> (http://support.microsoft.com/kb/878501/en-us) that addresses this
>> problem (not saying, however, that one table might work and the second
>> not). Microsoft says that the resolution is to install SP4 of the
>> SQL-server 2000. I did that, but it didn't help at all; there is exactly
>> the same behaviour as before. What is wrong here, and what should be
>> done?
>>
>
>


Re: Identity_Insert Problem
"Alex Dybenko" <alexdyb[ at ]PLEASE.cemi.NO.rssi.SPAM.ru> 6/1/2007 9:32:17 AM
Hi,
I think it fails, because there are 2 different connections - one for
pass-through query and second for linked table. As Sylvain wrote - I also
suggest to use intermediate table

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

"Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
news:eTrEkRBpHHA.4400[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
>> Did you try closing the first ODBCDirect workspace and reopening a new
>> one?
> Maybe this not, but a lot of other things. Instead of using an ODBCdirect
> workspace a used a pass through query, so there is no ODBCdirect
> workspace. Or a opened a new (jet) workspace for the bulk query only after
> setting the IDENTITY_INSERT. Nothing helped. I then thought about two
> alternative technologies, namely (1) constructing a script that imports
> all the data (encouraged by a former answer in this newsgroup), and (2)
> using SQL-DMO. I guessed to have (in my situation) a little bit less work
> with SQL-DMO, so I tried this and it worked. Of course (like it would also
> be with a script) the transfer is then done record by record instead with
> one single query for a whole table. But at least it works now.
>
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:uNiKQGvoHHA.4400[ at ]TK2MSFTNGP03.phx.gbl...
>> Did you try closing the first ODBCDirect workspace and reopening a new
>> one?
>>
>> A second possibility would be to use an intermediate table on SQL-Server
>> without an identity column and copy first to this table before copying
>> from it to the real table. The second step can be done entirely on the
>> SQL-Server, so it should be very fast.
>>
>> A final possibility is that Access is opening more than a single
>> connection. I don't remember how exactly the ODBCDirect is working but
>> maybe you will have some hints if you take a look with the SQL-Server
>> profiler. It could also be a problem with the Connections Pool, hard to
>> say. With many providers, you can deactivate the connections pool, so
>> maybe there is something there to look at.
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Technologies Virtual-PC
>> E-mail: sylvain aei ca (fill the blanks, no spam please)
>>
>>
>> "Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
>> news:OTM7HRpoHHA.3952[ at ]TK2MSFTNGP03.phx.gbl...
>>>I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
>>>several tables from an Access DB to an SQL DB. In an mdb-program I link
>>>all the tables, so that I have normal linked tables (the source) and
>>>odbc-linked tables (the target). The tables have an identity, so in a
>>>special ODBC-direct workspace I send the TSQL-statement "SET
>>>IDENTITY_INSERT mytable ON" (which seems to be successful, I checked
>>>that), then I execute an INSERT INTO-query on the linked tables for
>>>transferring all the data, then I send "SET IDENTITY_INSERT mytable OFF".
>>>Then comes the next table, and so on.
>>> For the first table everything is OK. The second table however failed
>>> when trying the INSERT INTO-query, giving the error "Cannot insert
>>> explicit value for identity column in table 'mytable2' when
>>> IDENTITY_INSERT is set to OFF". If I change the order of the first two
>>> tables, then again the one that executes first is successful and the one
>>> that comes after, failed.
>>> Now I found an article of Microsoft
>>> (http://support.microsoft.com/kb/878501/en-us) that addresses this
>>> problem (not saying, however, that one table might work and the second
>>> not). Microsoft says that the resolution is to install SP4 of the
>>> SQL-server 2000. I did that, but it didn't help at all; there is exactly
>>> the same behaviour as before. What is wrong here, and what should be
>>> done?
>>>
>>
>>
>
>

Re: Identity_Insert Problem
<david[ at ]epsomdotcomdotau> 6/9/2007 1:35:38 AM
1) Try it without "Identity Insert". Access 2000/Jet 4.0 does that
automatically for you. (Access 97 did not).

2) Access 2000/Jet 4.0 frequently does multiple connections
to SQL server which are totally inappropriate, as in this case.
(Access 97 did not).

3) Use ADO instead of DAO.

4) If you can't use ADO, try using a separate DAO object for
every action.
Set dbe = createobject(dao.dbengine.36")
Do not use an application object like CurrentDB or dbEngine
or OpenDatabase. Those are just copies of
Application.CurrentDB,
Application.dbEngine
etc.
You have to check that the ODBC action is complete before
closing the object: use synchronous actions, (no transactions
of course).

You can't use ODBCdirect to copy data from an mdb to
SQL Server - ODBCdirect can't connect to an mdb.

You can use linked tables from SQL Server to an mdb (you
can create the links in SQL Server instead of in an mdb), but
this feature is normally disabled because of the security risk
created by enabling access on a server to the powerful JET
engine. You could use ODBCdirect or stored procedures
to copy between tables in SQL Server.

You can't use DAO transactions for much with SQL Server,
because it is broken in Access 2000/Jet 4
(Access 97 was ok)

(david)

"Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
news:OTM7HRpoHHA.3952[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
> several tables from an Access DB to an SQL DB. In an mdb-program I link
all
> the tables, so that I have normal linked tables (the source) and
odbc-linked
> tables (the target). The tables have an identity, so in a special
> ODBC-direct workspace I send the TSQL-statement "SET IDENTITY_INSERT
mytable
> ON" (which seems to be successful, I checked that), then I execute an
INSERT
> INTO-query on the linked tables for transferring all the data, then I send
> "SET IDENTITY_INSERT mytable OFF". Then comes the next table, and so on.
> For the first table everything is OK. The second table however failed when
> trying the INSERT INTO-query, giving the error "Cannot insert explicit
value
> for identity column in table 'mytable2' when IDENTITY_INSERT is set to
OFF".
> If I change the order of the first two tables, then again the one that
> executes first is successful and the one that comes after, failed.
> Now I found an article of Microsoft
> (http://support.microsoft.com/kb/878501/en-us) that addresses this problem
> (not saying, however, that one table might work and the second not).
> Microsoft says that the resolution is to install SP4 of the SQL-server
2000.
> I did that, but it didn't help at all; there is exactly the same behaviour
> as before. What is wrong here, and what should be done?
>
>


Re: Identity_Insert Problem
Yvonne Anderson <yvonnemichele[ at ]noos.fr> 6/12/2007 10:41:01 AM
What it is this group, and why is it appearing on my computer?

Yvonne Michele Anderson
yvonnemichele[ at ]noos.fr


On 9/06/07 3:35, in article #Tv$aWjqHHA.4132[ at ]TK2MSFTNGP05.phx.gbl,
"david[ at ]epsomdotcomdotau" <david[ at ]epsomdotcomdotau> wrote:

[Quoted Text]
> 1) Try it without "Identity Insert". Access 2000/Jet 4.0 does that
> automatically for you. (Access 97 did not).
>
> 2) Access 2000/Jet 4.0 frequently does multiple connections
> to SQL server which are totally inappropriate, as in this case.
> (Access 97 did not).
>
> 3) Use ADO instead of DAO.
>
> 4) If you can't use ADO, try using a separate DAO object for
> every action.
> Set dbe = createobject(dao.dbengine.36")
> Do not use an application object like CurrentDB or dbEngine
> or OpenDatabase. Those are just copies of
> Application.CurrentDB,
> Application.dbEngine
> etc.
> You have to check that the ODBC action is complete before
> closing the object: use synchronous actions, (no transactions
> of course).
>
> You can't use ODBCdirect to copy data from an mdb to
> SQL Server - ODBCdirect can't connect to an mdb.
>
> You can use linked tables from SQL Server to an mdb (you
> can create the links in SQL Server instead of in an mdb), but
> this feature is normally disabled because of the security risk
> created by enabling access on a server to the powerful JET
> engine. You could use ODBCdirect or stored procedures
> to copy between tables in SQL Server.
>
> You can't use DAO transactions for much with SQL Server,
> because it is broken in Access 2000/Jet 4
> (Access 97 was ok)
>
> (david)
>
> "Lorenz Ingold" <l.ingold[ at ]winvs.ch> wrote in message
> news:OTM7HRpoHHA.3952[ at ]TK2MSFTNGP03.phx.gbl...
>> I have Access 2003 and SQL-Server 2000 SP3a. I want to copy the data of
>> several tables from an Access DB to an SQL DB. In an mdb-program I link
> all
>> the tables, so that I have normal linked tables (the source) and
> odbc-linked
>> tables (the target). The tables have an identity, so in a special
>> ODBC-direct workspace I send the TSQL-statement "SET IDENTITY_INSERT
> mytable
>> ON" (which seems to be successful, I checked that), then I execute an
> INSERT
>> INTO-query on the linked tables for transferring all the data, then I send
>> "SET IDENTITY_INSERT mytable OFF". Then comes the next table, and so on.
>> For the first table everything is OK. The second table however failed when
>> trying the INSERT INTO-query, giving the error "Cannot insert explicit
> value
>> for identity column in table 'mytable2' when IDENTITY_INSERT is set to
> OFF".
>> If I change the order of the first two tables, then again the one that
>> executes first is successful and the one that comes after, failed.
>> Now I found an article of Microsoft
>> (http://support.microsoft.com/kb/878501/en-us) that addresses this problem
>> (not saying, however, that one table might work and the second not).
>> Microsoft says that the resolution is to install SP4 of the SQL-server
> 2000.
>> I did that, but it didn't help at all; there is exactly the same behaviour
>> as before. What is wrong here, and what should be done?
>>
>>
>
>

Home | Search | Terms | Imprint
Newsgroups Reader