Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Serve 2008 Does Not Return Identity Value

$
0
0

We just upgraded from Windows 2003/SQL2000 to Windows 2008R2/SQL200R2 and we are using a website in classic ASP.
We are running into a problem where SQL server stored procedure does not return identity value after doing an insert.

 


My Stored Procedure

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[myStoredProcedure] @FName AS VARCHAR(100),  @LName AS VARCHAR(100) 
AS DECLARE @CustId AS INT INSERT INTO myCustomers(FirstName,LastName) VALUES(@FName,@LName) SET @CustId = @@IDENTITY SELECT @CustId

My Table

CREATE TABLE [dbo].[myCustomers]( [CustomerID] [int] IDENTITY(1,1) NOT NULL, [FirstName] [varchar](50) NULL, [LastName] [varchar](50) NULL, CONSTRAINT [PK_myCustomers] PRIMARY KEY CLUSTERED 
( [CustomerID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


My ASP Code

<%
strConn = "Provider=SQLOLEDB;SERVER=mySERVER;Uid=myUserName;Pwd=myPassWord;Database=myDatabase"
set conn = server.createobject("ADODB.Connection")
conn.open strConn 
If Err.Number <> 0 then Response.Write Err.Number & "<br>" Response.Write Err.Description & "<br>"
Else Response.Write "Conned established<br>" 
End If 
strSQL = "exec myStoredProcedure 'myFirstName', 'MyLastName'"
SET RS  = conn.execute(strSQL)
CustID = RS("CustID")  & "<br>"
Response.Write "CustID = " & CustID 
RS.Close
SET RS = Nothing
conn.close
SET conn = nothing
Response.End
%>


My Error Message

Conned established
ADODB.Recordset error '800a0cc1' 
Item cannot be found in the collection corresponding to the requested name or ordinal.

myTest.asp, line 12 

 


Here is what I have tried I have so far:


1. If I comment the INSERT statement in stored procedure and hard code some value to @CustID such as @CustID=1000, it works.

2. If I DO NOT comment  INSERT statement in stored procedure and hard code some value to @CustID such as @CustID=1000, it gives the same error as above.

3. Same code with same stored procedure works with Windows 2003/SQL2000.


Please help.

 




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>