473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Access Bug with SQL Server identity columns

I don't know if this has been reported before but it appears to be a
bug with Access.

If I create two tables both with an identity column then create an
insert trigger on table1 that inserts a related record into table2, now
create a form on table1 with a subform on table2. Insert records into
the main form to your heart's content and everything's fine, each main
record automatically gets a child record and so far the identity
columns are nice and sequential with no gaps, which is good for testing
the next bit (gaping holes in the sequentialness might not show up the
problem easily)

Now truncate table2 (note: use truncate table so that the identity seed
is reset)

Now enter a new record into the form, when it saves, it will jump back
to record 1, well actually it thinks (according to the nav bar) it's on
the last record but the data is from the record with the id of 1. do it
again it will jump to record 2, etc.

What's happening here is that Access appears to be retrieving
@@IDENTITY from the server and that contains the ID of table2 that was
inserted by the trigger. If the id of table2 doesn't exist in table1,
then the main form stays at the record just inserted (strange, I
predicted it would go all #deleted on me).

The problem only arises if the trigger inserts an ID into the sub table
that also exists as an ID in the main table so you can see you might
never come across the problem.

I can't say what Access does internally but it appears it's using
@@IDENTITY when a fix for this would be for it to use SCOPE_IDENTITY().

So I have a bug, probable cause and a fix, who do I send that to that
doesn't want to charge me £70 for the privilege?

Nov 13 '05 #1
17 3546
ADP or MDB and ODBC/whatever?

Nov 13 '05 #2
ADP or MDB and ODBC/whatever?

Nov 13 '05 #3
On 5 Aug 2005 03:25:29 -0700, "Trevor Best"
<go**********@besty.org.uk> wrote:

Try to reproduce using the beta version of SQL Server 2005. Then maybe
MSFT would be interested. I'm pretty sure there is a way to
participate in the beta program.
OTOH this may be strictly an Access bug, and not a SQL Server one.

Were your tables in a 1:M relation? That's what subforms are most
often used for.

-Tom.
I don't know if this has been reported before but it appears to be a
bug with Access.

If I create two tables both with an identity column then create an
insert trigger on table1 that inserts a related record into table2, now
create a form on table1 with a subform on table2. Insert records into
the main form to your heart's content and everything's fine, each main
record automatically gets a child record and so far the identity
columns are nice and sequential with no gaps, which is good for testing
the next bit (gaping holes in the sequentialness might not show up the
problem easily)

Now truncate table2 (note: use truncate table so that the identity seed
is reset)

Now enter a new record into the form, when it saves, it will jump back
to record 1, well actually it thinks (according to the nav bar) it's on
the last record but the data is from the record with the id of 1. do it
again it will jump to record 2, etc.

What's happening here is that Access appears to be retrieving
@@IDENTITY from the server and that contains the ID of table2 that was
inserted by the trigger. If the id of table2 doesn't exist in table1,
then the main form stays at the record just inserted (strange, I
predicted it would go all #deleted on me).

The problem only arises if the trigger inserts an ID into the sub table
that also exists as an ID in the main table so you can see you might
never come across the problem.

I can't say what Access does internally but it appears it's using
@@IDENTITY when a fix for this would be for it to use SCOPE_IDENTITY().

So I have a bug, probable cause and a fix, who do I send that to that
doesn't want to charge me £70 for the privilege?


Nov 13 '05 #4
On 5 Aug 2005 03:25:29 -0700, "Trevor Best"
<go**********@besty.org.uk> wrote:

Try to reproduce using the beta version of SQL Server 2005. Then maybe
MSFT would be interested. I'm pretty sure there is a way to
participate in the beta program.
OTOH this may be strictly an Access bug, and not a SQL Server one.

Were your tables in a 1:M relation? That's what subforms are most
often used for.

-Tom.
I don't know if this has been reported before but it appears to be a
bug with Access.

If I create two tables both with an identity column then create an
insert trigger on table1 that inserts a related record into table2, now
create a form on table1 with a subform on table2. Insert records into
the main form to your heart's content and everything's fine, each main
record automatically gets a child record and so far the identity
columns are nice and sequential with no gaps, which is good for testing
the next bit (gaping holes in the sequentialness might not show up the
problem easily)

Now truncate table2 (note: use truncate table so that the identity seed
is reset)

Now enter a new record into the form, when it saves, it will jump back
to record 1, well actually it thinks (according to the nav bar) it's on
the last record but the data is from the record with the id of 1. do it
again it will jump to record 2, etc.

What's happening here is that Access appears to be retrieving
@@IDENTITY from the server and that contains the ID of table2 that was
inserted by the trigger. If the id of table2 doesn't exist in table1,
then the main form stays at the record just inserted (strange, I
predicted it would go all #deleted on me).

The problem only arises if the trigger inserts an ID into the sub table
that also exists as an ID in the main table so you can see you might
never come across the problem.

I can't say what Access does internally but it appears it's using
@@IDENTITY when a fix for this would be for it to use SCOPE_IDENTITY().

So I have a bug, probable cause and a fix, who do I send that to that
doesn't want to charge me £70 for the privilege?


Nov 13 '05 #5
MDB/ODBC

Nov 13 '05 #6
MDB/ODBC

Nov 13 '05 #7
Originally 1:n when first found, my test database I built didn't have
the relationship in

Nov 13 '05 #8
Originally 1:n when first found, my test database I built didn't have
the relationship in

Nov 13 '05 #9
Just tried in ADP, did the same thing.

(sorry if this is a duplicate post, Google logged me out when I
submitted it)

Nov 13 '05 #10
Just tried in ADP, did the same thing.

(sorry if this is a duplicate post, Google logged me out when I
submitted it)

Nov 13 '05 #11
> Try to reproduce using the beta version of SQL Server 2005

I have the beta, when I restore a database into it from 2000, only half
the database gets restored, tables have missing data, some tables
missing, right mess. They might want to address the fundimental issues
like that before the obscure ones like my OP :-)

I'm pretty sure it's an Access bug anyway, if I insert using Query
Analyser, both @@IDENTITY and SCOPE_IDENTITY() return the expected
values, i.e. @@IDENTITY returns the ID from table2 and SCOPE_IDENTITY()
returns the ID of table1.

Same thing in ADP or MDB so would suggest Access and not any of it's
middleware like ODBC/ADO/DAO, etc.

Nov 13 '05 #12
> Try to reproduce using the beta version of SQL Server 2005

I have the beta, when I restore a database into it from 2000, only half
the database gets restored, tables have missing data, some tables
missing, right mess. They might want to address the fundimental issues
like that before the obscure ones like my OP :-)

I'm pretty sure it's an Access bug anyway, if I insert using Query
Analyser, both @@IDENTITY and SCOPE_IDENTITY() return the expected
values, i.e. @@IDENTITY returns the ID from table2 and SCOPE_IDENTITY()
returns the ID of table1.

Same thing in ADP or MDB so would suggest Access and not any of it's
middleware like ODBC/ADO/DAO, etc.

Nov 13 '05 #13
On 5 Aug 2005 07:42:23 -0700, "Trevor Best"
<go**********@besty.org.uk> wrote:

Sounds like a bug to me. I could understand how the MSFT developers
and testers missed this one.
Perhaps you have the option of going ADP, and writing a sproc that
returns the correct value to you.

-Tom.
Try to reproduce using the beta version of SQL Server 2005


I have the beta, when I restore a database into it from 2000, only half
the database gets restored, tables have missing data, some tables
missing, right mess. They might want to address the fundimental issues
like that before the obscure ones like my OP :-)

I'm pretty sure it's an Access bug anyway, if I insert using Query
Analyser, both @@IDENTITY and SCOPE_IDENTITY() return the expected
values, i.e. @@IDENTITY returns the ID from table2 and SCOPE_IDENTITY()
returns the ID of table1.

Same thing in ADP or MDB so would suggest Access and not any of it's
middleware like ODBC/ADO/DAO, etc.


Nov 13 '05 #14
Yes, this is a problem with -all- microsoft database access libraries for MS
SQL Server. Even though SQL Server since version 2000 has had a reliable
method for getting the last identity value in the current context, no driver
uses it.

The work-around I've always used is to make sure that no trigger inserts into
a table that contains an IDENTITY column, and use some other unique identifier
instead. I just saw a better reloy on another newsgroup recently, though.

It turns out that, within the trigger, you can select @@INENTITY to a local
variable, then select it back into @@IDENTITY at the end of the trigger
procedure, thus putting @@IDENTITY back to the value Access will need to see
afterward.

On 5 Aug 2005 03:25:29 -0700, "Trevor Best" <go**********@besty.org.uk> wrote:
I don't know if this has been reported before but it appears to be a
bug with Access.

If I create two tables both with an identity column then create an
insert trigger on table1 that inserts a related record into table2, now
create a form on table1 with a subform on table2. Insert records into
the main form to your heart's content and everything's fine, each main
record automatically gets a child record and so far the identity
columns are nice and sequential with no gaps, which is good for testing
the next bit (gaping holes in the sequentialness might not show up the
problem easily)

Now truncate table2 (note: use truncate table so that the identity seed
is reset)

Now enter a new record into the form, when it saves, it will jump back
to record 1, well actually it thinks (according to the nav bar) it's on
the last record but the data is from the record with the id of 1. do it
again it will jump to record 2, etc.

What's happening here is that Access appears to be retrieving
@@IDENTITY from the server and that contains the ID of table2 that was
inserted by the trigger. If the id of table2 doesn't exist in table1,
then the main form stays at the record just inserted (strange, I
predicted it would go all #deleted on me).

The problem only arises if the trigger inserts an ID into the sub table
that also exists as an ID in the main table so you can see you might
never come across the problem.

I can't say what Access does internally but it appears it's using
@@IDENTITY when a fix for this would be for it to use SCOPE_IDENTITY().

So I have a bug, probable cause and a fix, who do I send that to that
doesn't want to charge me £70 for the privilege?


Nov 13 '05 #15
Steve Jorgensen wrote:
Yes, this is a problem with -all- microsoft database access libraries for MS
SQL Server. Even though SQL Server since version 2000 has had a reliable
method for getting the last identity value in the current context, no driver
uses it.

The work-around I've always used is to make sure that no trigger inserts into
a table that contains an IDENTITY column, and use some other unique identifier
instead. I just saw a better reloy on another newsgroup recently, though.

It turns out that, within the trigger, you can select @@INENTITY to a local
variable, then select it back into @@IDENTITY at the end of the trigger
procedure, thus putting @@IDENTITY back to the value Access will need to see
afterward.


Thanks, do you have an example of that trigger? I get errors when I try
to set it...

set @@IDENTITY = @ID -- Incorrect syntax near '@@IDENTITY'
select @@IDENTITY = @ID -- Incorrect syntax near '='

--
[OO=00=OO]
Nov 13 '05 #16
On Sat, 06 Aug 2005 11:00:55 +0100, Trevor Best <no****@besty.org.uk> wrote:
Steve Jorgensen wrote:
Yes, this is a problem with -all- microsoft database access libraries for MS
SQL Server. Even though SQL Server since version 2000 has had a reliable
method for getting the last identity value in the current context, no driver
uses it.

The work-around I've always used is to make sure that no trigger inserts into
a table that contains an IDENTITY column, and use some other unique identifier
instead. I just saw a better reloy on another newsgroup recently, though.

It turns out that, within the trigger, you can select @@INENTITY to a local
variable, then select it back into @@IDENTITY at the end of the trigger
procedure, thus putting @@IDENTITY back to the value Access will need to see
afterward.


Thanks, do you have an example of that trigger? I get errors when I try
to set it...

set @@IDENTITY = @ID -- Incorrect syntax near '@@IDENTITY'
select @@IDENTITY = @ID -- Incorrect syntax near '='


I checked the other post again, and it looks like there is a sneaky trick you
have to do to contrive to get @@IDENTITY back to what it was...

EXECUTE (N'SELECT Identity (Int, ' + Cast(@myid As Varchar(10)) + ',1) AS id
INTO #Tmp'

However, the same post implies that it might fix the problem to just make sure
the first thing your trigger does is SET NOCOUNT ON.
Nov 13 '05 #17
Steve Jorgensen wrote:
EXECUTE (N'SELECT Identity (Int, ' + Cast(@myid As Varchar(10)) + ',1) AS id
INTO #Tmp'
Works a charm, thanks. Although it didn't like the concatenation there
so I made a varchar variable, built the SQL then executed that.

set @strSQL = 'SELECT Identity (Int, ' + Cast(@id As Varchar(10)) + ',1)
AS id INTO #Tmp'
execute (@strSQL)
However, the same post implies that it might fix the problem to just make sure
the first thing your trigger does is SET NOCOUNT ON.


That didn't work. First one did so problem solved, thanks again.

--
[OO=00=OO]
Nov 13 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
4
by: Fabian von Romberg | last post by:
Hi, I have installed Sql Reporting Services on 2 machines, one is WIN 2000 PRO and the other one is WIN 2000 ADV. SERVER. When I try to access a report using the webbrowser, I get the following...
2
by: meyvn77 | last post by:
Background: I'm new at SQL Server (no experience, zip, nada) but getting pretty good with developing applications in Access(VBA) and in VB using ADO.... Currently I use access to and GIS...
0
by: Trevor Best | last post by:
I don't know if this has been reported before but it appears to be a bug with Access. If I create two tables both with an identity column then create an insert trigger on table1 that inserts a...
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
17
by: DaveG | last post by:
Hi all I am planning on writing a stock and accounts program for the family business, I understand this is likely to take close to 2 years to accomplish. The stock is likely to run into over a...
15
by: Marcus | last post by:
I created a VB.Net 1.1 application that iterates through all the tables in any basic Access 2000 database passed to it and generates the same table structure in a SQL Server Express database. The...
6
by: royan | last post by:
Help please! I have the same problem which this post ...
2
by: Dave | last post by:
I have a web app that needs to access a folder on a different server. The other server "IS" on a domain. I tried using DirectoryInfo, even with a Virtual Directory, only to find that it pertains...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.