Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 10th, 2008, 03:26 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default Working Stored Proc fails in ASP.Net

I have a stored procedure I wrote in a SQLExpress 2005 Database that works fine when I run it from the SQL Server Manager Console but fails when I call it from my web application.

In the application I am using System.Data.SqlClient with the SqlConnection, SqlCommand and SqlDataReader classes. The procedure takes 3 parameters which I pass in.

When I run it in my application I get this message:

Cannot insert explicit value for identity column in table '#tmpAnalyzers

The stored procedure has IDENTITY_INSERT set on for that table so there is no problem running the stored procedure.

I read something about SQLClient having problem with SET commands but as this is a stored procedure it should not be an issue.

Does anyone know why it fails and how to make it work?

Thanks,


What you don't know can hurt you!
__________________
What you don\'t know can hurt you!
 
Old June 12th, 2008, 01:49 PM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
Default

Hi David. Topic moved per your request and replies about moving it deleted. :)

Jim Minatel
Acquisitions Director
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Wrox online library: http://wrox.books24x7.com
 
Old June 12th, 2008, 02:03 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

I don't know what the problem actually is, but I have to ask... Why on earth would you build a Temp Table with an IDENTITY column only to override it? On the surface, that just doesn't sound right from the "git".

--Jeff Moden
 
Old June 12th, 2008, 05:00 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jeff, I agree 100% with you. The problem is when you build a temp table using:

SELECT * INTO #tmp FROM SOMETABLE ...

and SOMETABLE has an identity column in it SQLServer assumes you want that column in the temporary table to be identity as well. As usual, there are a number of ways to skin a cat. One would be to cast the offending column into a bigint type...

SELECT Cast(MYIDCOL as bigint) AS MYIDCOL, ANOTHER_COL, ... INTO #tmp FROM SOMETABLE ...

However, the solution to my problem was to take my right palm and smack it firmly against my forehead! When I originally created the stored procedure I had neglected to prepend the schema to the procedure name. I realized immediately that I had goofed and repaired that. However, at the time, I couldn't find the wrongly created procedure. In my application I had also neglected the schema but didn't pick up on that right away. As you can imagine, any changes I made to the procedure with the correct schema were not reflected in the one under the dbo schema or in my application! I'm still trying to get the egg off of my face.

What you don't know can hurt you!
 
Old June 12th, 2008, 07:16 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Well explained, David. Thanks for the feedback. You have an egg problem... me... I keep getting a tennis **** stuck in my mouth :D

--Jeff Moden
 
Old June 12th, 2008, 07:19 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Now isn't that funny... this forum censors the word s*h*o*e

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Proc that returns a value elygp SQL Server 2000 4 May 9th, 2007 01:05 AM
Calling an insert stored proc from a select stored dzitam SQL Language 10 April 2nd, 2007 12:39 PM
How to get value from stored proc busybee ASP.NET 1.0 and 1.1 Basics 4 April 2nd, 2006 01:06 AM
working with stored procedure and asp rashoova Classic ASP Databases 0 February 1st, 2006 10:19 AM
stored proc working local and not remote jazzlover2002 SQL Server 2000 3 October 25th, 2003 02:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.