Need @@identity in an ASP

Posted on 1998-10-07
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?
Question by:rickpaul
  • 2

Expert Comment

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.

Accepted Solution

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

Author Comment

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

Expert Comment

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.

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 121
SQL Mirror and Replication 5 18
Ranking Based On Value 3 29
Distinct values from two tables 14 20
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now