Solved

Need @@identity in an ASP

Posted on 1998-10-07
4
204 Views
Last Modified: 2010-03-19
I execute a query that reads:
INSERT INTO table (field1, field2) VALUES (2,2)
   SELECT @@identity as ident
If I do that in the Interdev data environment, it returns a table with one column labeled "ident" and the value of the identity field just assigned. When I do the same thing in my ASP then try to access the recordset("ident"), I get "invalid procedure on closed object". Any ideas?
0
Comment
Question by:rickpaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:abhinavm
ID: 1090448
I think your connection to database is lost due to some reason because i have tried the same code and its working fine.
0
 
LVL 1

Accepted Solution

by:
kdimmock earned 200 total points
ID: 1090449
Try this ...

set nocount on
INSERT INTO table (field1, field2) VALUES (2,2)
   SELECT @@identity as ident
set nocount off
0
 

Author Comment

by:rickpaul
ID: 1090450
Perfect! I wonder if you can tell me where I might have found that in the documentation?
0
 
LVL 1

Expert Comment

by:kdimmock
ID: 1090451
It was one of those things I found by trial and error. I needed to do the same as you and was getting the same problems as you.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question