473,758 Members | 5,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1070
Well,
obviously (or perhaps not so) there is something wrong with your code. Also,
I'm not familiar with "IDENT_CURR ENT" - @@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******** *************** ***********@m44 g2000hsc.google groups.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*******@dont doit.yahoo.comw rote in message
news:A6******** *************** ***********@mic rosoft.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_CURR ENT"
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******** *************** ***********@m44 g2000hsc.google groups.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...@markNOSPA Mrae.netwrote:
"Tom P." <padilla.he...@ gmail.comwrote in message

news:58******** *************** ***********@m44 g2000hsc.google groups.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\Padilla H].[spCreateAcquisi tion]
@FileUploadName varchar (50),
@AcquisitionID int
AS

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

-- Variable Declarations
DECLARE @InternalAcquis itionID int;

--BEGIN TRAN

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

--COMMIT

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

--Select the information back out for the entire row
SELECT
InternalAcquisi tionID,
AcquisitionID,
ServicerID,
'',
FileUploadDate,
TotalLoanCount,
LoansAssigned,
TotalLoanCount - LoansAssigned AS LoansUnassigned ,
TotalIndexes,
UnmatchedIndexe s,
TotalIndexes - UnmatchedIndexe s AS MatchedIndexes,
TotalProductCod es,
UnmatchedProduc tCodes,
TotalProductCod es - UnmatchedProduc tCodes AS MatchedProductC odes,
LastProcessedTi me,
Acquisition.Acq uisitionStatusC ode,
[Description],
[Filename]
FROM
Acquisition
INNER JOIN AcquisitionStat usCode
ON Acquisition.Acq uisitionStatusC ode =
AcquisitionStat usCode.Acquisit ionStatusCode
WHERE
InternalAcquisi tionID = @InternalAcquis itionID
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******** *************** ***********@l42 g2000hsc.google groups.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 @InternalAcquis itionID = IDENT_CURRENT(' Acquisition');
SET @InternalAcquis itionID = 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...@markNOSPA Mrae.netwrote:
"Tom P." <padilla.he...@ gmail.comwrote in message

news:84******** *************** ***********@l42 g2000hsc.google groups.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 @InternalAcquis itionID = IDENT_CURRENT(' Acquisition');

SET @InternalAcquis itionID = 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_IDENTIT Y():
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******** *************** ***********@8g2 000hse.googlegr oups.com...
On Sep 22, 7:22 am, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
"Tom P." <padilla.he...@ gmail.comwrote in message

news:84******** *************** ***********@l42 g2000hsc.google groups.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 @InternalAcquis itionID = IDENT_CURRENT(' Acquisition');

SET @InternalAcquis itionID = 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.nos pamwrote in message
news:%2******** ********@TK2MSF TNGP04.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_IDENTIT Y():
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
2079
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 to get a working system just about finished. I am building an interface for our customer service folks to use to manage registered customers and am seeing some weird behavior.
13
3806
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 counter functionality and read/insert some data in a MS Access database on that Windows 2003 server. The weird part is, as long as the web page is very short in size, I can hit the refresh button and Internet Explorer will reload the page and display...
1
2104
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 content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
0
1157
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 content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
1
1553
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, then enters valid username and password that are checked versus a db table, if the info is ok i execute SetAuthCookie(xxx, False) then i open a new window which displays the home page, all is working fine...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.