C
Carlo Razzeto
Hello, I'm currenly in the process of writing a Database abstraction class
that will support MySql, MS-SQL and OLEDB. In the abstract base class, I
have a public read only property LastAutoID UInt64 deffined. The field
behind this property is updated every time the end program calls the
ExecuteNonQuery() method (directly or indirectly).
My problem is that the SqlServer specific class is failing to retrive the
auto id, for some reason the query keeps returning DB null when I try to
populate the auto id field, forcing me to set 0. So far I've used the Sql
Server Profiler utility to confirm the fact that indeed, when I execute the
SCOPE_IDENTITY query it is on the same connection as the INSERT query (which
makes sense as by default my class disables Connection Pooling and enables a
Singleton pattern, never closes a connection unless requested by the end
programmer and reference count on the connection buffer is 0).
Now, for the wierd part... If I use the @@IDENTITY method in the query, I
get the auto number. Now, here's everything else that might be important.
First, after doing some reasearch I found that it is adventagous to cast the
result of the SCOPE_IDENTITY method as an int, so I tried that and casting
it as a bigint with no results.
Next, I realized that in my testing I was not specificlly naming at table, I
was just opening a connection and specifying the table using
<database>..<table>, so I switched over to connecting specifically to the
database and not specifying the database in the insert query, however that
produced no better results.
I've also posted this question to
microsoft.public.sqlserver.programming and gotten good advice, however
nothing that helps.
that will support MySql, MS-SQL and OLEDB. In the abstract base class, I
have a public read only property LastAutoID UInt64 deffined. The field
behind this property is updated every time the end program calls the
ExecuteNonQuery() method (directly or indirectly).
My problem is that the SqlServer specific class is failing to retrive the
auto id, for some reason the query keeps returning DB null when I try to
populate the auto id field, forcing me to set 0. So far I've used the Sql
Server Profiler utility to confirm the fact that indeed, when I execute the
SCOPE_IDENTITY query it is on the same connection as the INSERT query (which
makes sense as by default my class disables Connection Pooling and enables a
Singleton pattern, never closes a connection unless requested by the end
programmer and reference count on the connection buffer is 0).
Now, for the wierd part... If I use the @@IDENTITY method in the query, I
get the auto number. Now, here's everything else that might be important.
First, after doing some reasearch I found that it is adventagous to cast the
result of the SCOPE_IDENTITY method as an int, so I tried that and casting
it as a bigint with no results.
Next, I realized that in my testing I was not specificlly naming at table, I
was just opening a connection and specifying the table using
<database>..<table>, so I switched over to connecting specifically to the
database and not specifying the database in the insert query, however that
produced no better results.
I've also posted this question to
microsoft.public.sqlserver.programming and gotten good advice, however
nothing that helps.