J
jagb
Scenario:
Transactional replication with queued updates using SQL Server 2005 SP1 (the
problem also happens on SQL 2000).
Some tables with identity key columns are published to subscribers.
Identity intervals management are set to default (10000 for publisher, 1000
for subscribers, 80%)
Access 2003 all SPs applied using ADP connects to a subscriber.
No forms, just open one of these tables with identity as primary key and try
to insert a record.
The following error message appears:
"The data was added to the database but the data won't be displayed in the
form because it doesn't satisfy the criteria in the underlying record
source."
According to http://support.microsoft.com/kb/291091/en-us :
[...]When inserting records into a Microsoft SQL Server database from an
ADP, Microsoft Access tries to reselect the newly inserted record to verify
that it was inserted correctly. To do this, Microsoft Access calls the
@@IDENTITY function to determine the Primary Key value of the newly inserted
record so that it knows which record to retrieve. Microsoft Access then
reselects the record based on that value.[...]
That point has been verified by using SQL Profiler. We can see that 'select
@@identity' is thrown by MS Access to SQL Server to retrieve the last
identity value inserted but the returned value is incorrect. This behaviour
is hard coded within MS Access, I am not talking about user defined code
inside a form or vb module.
The problem is that @@identity is the wrong function to be used. SQL Server
deploys triggers to subscribers in order to support replication and it seems
that inside those triggers there are insertions to system tables that also
use identity as key column, thus, invalidating the query for @@identity that
is done by MS Access afterwards. The corect funcion that MS Access should
query is SCOPE_IDENTITY() (see SQL BOL for information on this function).
Having said that (I think this is a MS Access bug) and before any SP or
hotfix solves the problem... How do you manage tables with identities when
you need to replicate them? Has someone any workaround for this problem? Is
not using identities anymore the solution? Any comments are welcome.
Thanks in advance and regards.
Transactional replication with queued updates using SQL Server 2005 SP1 (the
problem also happens on SQL 2000).
Some tables with identity key columns are published to subscribers.
Identity intervals management are set to default (10000 for publisher, 1000
for subscribers, 80%)
Access 2003 all SPs applied using ADP connects to a subscriber.
No forms, just open one of these tables with identity as primary key and try
to insert a record.
The following error message appears:
"The data was added to the database but the data won't be displayed in the
form because it doesn't satisfy the criteria in the underlying record
source."
According to http://support.microsoft.com/kb/291091/en-us :
[...]When inserting records into a Microsoft SQL Server database from an
ADP, Microsoft Access tries to reselect the newly inserted record to verify
that it was inserted correctly. To do this, Microsoft Access calls the
@@IDENTITY function to determine the Primary Key value of the newly inserted
record so that it knows which record to retrieve. Microsoft Access then
reselects the record based on that value.[...]
That point has been verified by using SQL Profiler. We can see that 'select
@@identity' is thrown by MS Access to SQL Server to retrieve the last
identity value inserted but the returned value is incorrect. This behaviour
is hard coded within MS Access, I am not talking about user defined code
inside a form or vb module.
The problem is that @@identity is the wrong function to be used. SQL Server
deploys triggers to subscribers in order to support replication and it seems
that inside those triggers there are insertions to system tables that also
use identity as key column, thus, invalidating the query for @@identity that
is done by MS Access afterwards. The corect funcion that MS Access should
query is SCOPE_IDENTITY() (see SQL BOL for information on this function).
Having said that (I think this is a MS Access bug) and before any SP or
hotfix solves the problem... How do you manage tables with identities when
you need to replicate them? Has someone any workaround for this problem? Is
not using identities anymore the solution? Any comments are welcome.
Thanks in advance and regards.