473,395 Members | 2,253 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,395 software developers and data experts.

Weird problem.

I have a webpage that takes user data and sends it to a stored
procedure that inserts a row in a table then returns the ID of that
row for display.

The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.

The dataset is not getting populated. The dataset has a DataTable that
gets created and the DataTable has the columns named correctly
according to the final select but there's no data in the table.

I've tried SET NOCOUNT ON, I've tried READ UNCOMMITTED, I've tried
COMMITing after the insert...

I've tried just limiting the data to return the ID and I'll do another
select later but I can't even get the ID out.

I just don't get it.

If anyone has any ideas please let me know. If there's anything else
you need to know just ask.

Tom P.
Sep 19 '08 #1
8 1045
Well,
obviously (or perhaps not so) there is something wrong with your code. Also,
I'm not familiar with "IDENT_CURRENT" - @@IDENTITY will do this for SQL
Server. Do you want to post a short-but-complete code sample so that you can
get some help?
Peter

"Tom P." <pa***********@gmail.comwrote in message
news:58**********************************@m44g2000 hsc.googlegroups.com...
>I have a webpage that takes user data and sends it to a stored
procedure that inserts a row in a table then returns the ID of that
row for display.

The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.

The dataset is not getting populated. The dataset has a DataTable that
gets created and the DataTable has the columns named correctly
according to the final select but there's no data in the table.

I've tried SET NOCOUNT ON, I've tried READ UNCOMMITTED, I've tried
COMMITing after the insert...

I've tried just limiting the data to return the ID and I'll do another
select later but I can't even get the ID out.

I just don't get it.

If anyone has any ideas please let me know. If there's anything else
you need to know just ask.

Tom P.
Sep 21 '08 #2
"Peter Bromberg [C# MVP]" <pb*******@dontdoit.yahoo.comwrote in message
news:A6**********************************@microsof t.com...
>The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.

I'm not familiar with "IDENT_CURRENT"
http://msdn.microsoft.com/en-us/libr...8(SQL.90).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 21 '08 #3
"Tom P." <pa***********@gmail.comwrote in message
news:58**********************************@m44g2000 hsc.googlegroups.com...
I have a webpage that takes user data and sends it to a stored
procedure that inserts a row in a table then returns the ID of that
row for display.

The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.
And there's your problem. Use SELECT @@IDENTITY or, even better, SELECT
SCOPE_IDENTITY()...

http://msdn.microsoft.com/en-us/libr...5(SQL.90).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 21 '08 #4
On Sep 21, 2:57*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"Tom P." <padilla.he...@gmail.comwrote in message

news:58**********************************@m44g2000 hsc.googlegroups.com...
I have a webpage that takes user data and sends it to a stored
procedure that inserts a row in a table then returns the ID of that
row for display.
The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.

And there's your problem. Use SELECT @@IDENTITY or, even better, SELECT
SCOPE_IDENTITY()...

http://msdn.microsoft.com/en-us/libr...5(SQL.90).aspx

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Except I don't want just some random IDENTITY value I want the last
IDENTITY value that was inserted into this specific table. And what
would that have to do with the data being returned?

In any case this is the stroed Proc that is executing but not
returning rows:

CREATE PROC [IMAGING\PadillaH].[spCreateAcquisition]
@FileUploadName varchar (50),
@AcquisitionID int
AS

SET NOCOUNT ON
--SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

-- Variable Declarations
DECLARE @InternalAcquisitionID int;

--BEGIN TRAN

-- Insert initial values into table
INSERT INTO
Acquisition(
AcquisitionID,
[Filename],
AcquisitionStatusCode
)
VALUES
(
@AcquisitionID,
@FileUploadName,
'U' );

--COMMIT

-- Get the Identity value that was last used in this table
SET @InternalAcquisitionID = IDENT_CURRENT('Acquisition');

--Select the information back out for the entire row
SELECT
InternalAcquisitionID,
AcquisitionID,
ServicerID,
'',
FileUploadDate,
TotalLoanCount,
LoansAssigned,
TotalLoanCount - LoansAssigned AS LoansUnassigned,
TotalIndexes,
UnmatchedIndexes,
TotalIndexes - UnmatchedIndexes AS MatchedIndexes,
TotalProductCodes,
UnmatchedProductCodes,
TotalProductCodes - UnmatchedProductCodes AS MatchedProductCodes,
LastProcessedTime,
Acquisition.AcquisitionStatusCode,
[Description],
[Filename]
FROM
Acquisition
INNER JOIN AcquisitionStatusCode
ON Acquisition.AcquisitionStatusCode =
AcquisitionStatusCode.AcquisitionStatusCode
WHERE
InternalAcquisitionID = @InternalAcquisitionID
The insert happens, I've verified that. The select layout gets back to
the code, I've verified that. But there is no data row that gets back
to the code. The SQLServer is on a different box than the code is
running on. I have a page before this that is getting rows back from
this table so it CAN happen.

I've tried setting dirty reads (it's commented out above). I've tried
setting transactions and then commit (also commented out). I can't get
the data to come back from this procedure.

Tom P.
Sep 22 '08 #5
"Tom P." <pa***********@gmail.comwrote in message
news:84**********************************@l42g2000 hsc.googlegroups.com...
>>The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.

And there's your problem. Use SELECT @@IDENTITY or, even better, SELECT
SCOPE_IDENTITY()...

http://msdn.microsoft.com/en-us/libr...5(SQL.90).aspx

Except I don't want just some random IDENTITY value I want the last
IDENTITY value that was inserted into this specific table.
In which case, you're using the wrong function - read the docs...
SET @InternalAcquisitionID = IDENT_CURRENT('Acquisition');
SET @InternalAcquisitionID = SCOPE_IDENTITY();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 22 '08 #6
On Sep 22, 7:22*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"Tom P." <padilla.he...@gmail.comwrote in message

news:84**********************************@l42g2000 hsc.googlegroups.com...
>The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.
And there's your problem. Use SELECT @@IDENTITY or, even better, SELECT
SCOPE_IDENTITY()...
>http://msdn.microsoft.com/en-us/libr...5(SQL.90).aspx
Except I don't want just some random IDENTITY value I want the last
IDENTITY value that was inserted into this specific table.

In which case, you're using the wrong function - read the docs...
SET @InternalAcquisitionID = IDENT_CURRENT('Acquisition');

SET @InternalAcquisitionID = SCOPE_IDENTITY();

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
OK, someone's gonna have to explain that to me.

First off, it worked, thanks. (Dear God, thanks) But all that did is
confuse me even more.

IDENT_CURRENT was returning the correct identity. This is only now in
DEV so there are no others hitting the table to get confused with.
Besides, even if it wasn't returning the correct identity it should
have returned incorrect data, not nothing at all.

Does SCOPE_IDENTITY imply something about the transaction? Is that
what was happening? IDENT_CURRENT was abandonig the transaction or
something? But the identity it returned was correct... I've read both
articles and I don't get the difference. Please, if you could explain
better than MS I'd appreciate it.

And thanks again for the persistence in helping me.

Tom P.
Sep 22 '08 #7
SAL
The docs for IDENT_CURRENT:
Returns the last identity value generated for a specified table or view in
any session and any scope

That sounds like trouble to me but then, who am I right?

The docs say this for @@SCOPE_IDENTITY():
Returns the last identity value inserted into an identity column in the same
scope. A scope is a module: a stored procedure, trigger, function, or batch.
Therefore, two statements are in the same scope if they are in the same
stored procedure, function, or batch

Wow, sounds much safer to me...

S
"Tom P." <pa***********@gmail.comwrote in message
news:1e**********************************@8g2000hs e.googlegroups.com...
On Sep 22, 7:22 am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"Tom P." <padilla.he...@gmail.comwrote in message

news:84**********************************@l42g2000 hsc.googlegroups.com...
>The stored procedure does an insert then it uses IDENT_CURRENT to get
the identity of the row that was just inserted and selects the row
back out to display.
And there's your problem. Use SELECT @@IDENTITY or, even better, SELECT
SCOPE_IDENTITY()...
>http://msdn.microsoft.com/en-us/libr...5(SQL.90).aspx
Except I don't want just some random IDENTITY value I want the last
IDENTITY value that was inserted into this specific table.

In which case, you're using the wrong function - read the docs...
SET @InternalAcquisitionID = IDENT_CURRENT('Acquisition');

SET @InternalAcquisitionID = SCOPE_IDENTITY();

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
OK, someone's gonna have to explain that to me.

First off, it worked, thanks. (Dear God, thanks) But all that did is
confuse me even more.

IDENT_CURRENT was returning the correct identity. This is only now in
DEV so there are no others hitting the table to get confused with.
Besides, even if it wasn't returning the correct identity it should
have returned incorrect data, not nothing at all.

Does SCOPE_IDENTITY imply something about the transaction? Is that
what was happening? IDENT_CURRENT was abandonig the transaction or
something? But the identity it returned was correct... I've read both
articles and I don't get the difference. Please, if you could explain
better than MS I'd appreciate it.

And thanks again for the persistence in helping me.

Tom P.
Sep 26 '08 #8
"SAL" <SA*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

[please don't top-post]
The docs for IDENT_CURRENT:
Returns the last identity value generated for a specified table or view in
any session and any scope

That sounds like trouble to me but then, who am I right?

The docs say this for @@SCOPE_IDENTITY():
Returns the last identity value inserted into an identity column in the
same scope. A scope is a module: a stored procedure, trigger, function, or
batch. Therefore, two statements are in the same scope if they are in the
same stored procedure, function, or batch

Wow, sounds much safer to me...
Absolutely correct.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 26 '08 #9

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

Similar topics

3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
0
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
1
by: Strange Cat | last post by:
Hi everyone! I have a weird problem with FormsAuthentication. I have an app that works just fine with FormsAuthentication. The user requests the homepage, he is redirected to login page,...
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
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.