Solved

Session Definition and Use in SQL Server

Posted on 2004-04-24
7
276 Views
Last Modified: 2012-06-27
Have a website that will insert data via a stored procedure.  The stored procedure connects with the db, inserts the data, disconnects.  Periodically, will get an error message  that the identity_insert is off.  Yet, when execute again.. everything is fine.  

Would like to know how to prevent this error.  Should the stored procedure set Identity_Insert to on just before the insert or is there another reason for this message?

Thanxs,
Glass
0
Comment
Question by:Glass
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 10910439
That is weird--you shouldn't have to execute set identity in your stored proc to work around this.

How are you connecting to the database?
0
 
LVL 8

Expert Comment

by:plq
ID: 10911325
Weird indeed. I don't think there's a performance hit with doing set identity_insert on, so why not add it to the top of the sp anyway

But it would be nice to know why, thats pretty unusual behaviour.

afaik - If you are connecting through a component services object, your sessions will be cached, this may explain why its sometimes off and sometimes on, if you have another piece of code connecting and setting identity_insert to on, then it will be random whether its on or off depending on whether com+ created a new session or reused a cached session?
0
 
LVL 34

Expert Comment

by:arbert
ID: 10912519
"so why not add it to the top of the sp anyway "


Ya, I guess I would say figure it out and fix it--why risk the possibility of inserting a "stray" value into a table just because you allowed Idents to be inserted!

0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Author Comment

by:Glass
ID: 10914358
Plq,

Anyway to prevent reusing a cached session?

Thanxs,
Glass

Arbert,

My connection is done as follows:

Dim my Connection As New SqllConnection(ConfigurationSettings.AppSettings("connectionString")  

 execute stored procedure
 close connection


Any suggestions on how to approach debugging this issue which occurs only periodically...

Thanxs,
Glass

0
 
LVL 8

Accepted Solution

by:
plq earned 125 total points
ID: 10915843
Hi Glass,

Looking at the pooling and recycling options in com+ I couldn't really pick out one that would guarantee a new connection, yet for the last few years I've had it at the front of my mind that it was possible to force this, so I think I've read it somewhere !!!

I'd be inclined to search the source code for the application for identity_insert, just to try to understand if it is turned on and off in certain places without getting properly reset.
0
 

Author Comment

by:Glass
ID: 10917979
Thanxs....  Will look for the identity_insert in my stored procedures.

Glass
0
 
LVL 34

Assisted Solution

by:arbert
arbert earned 125 total points
ID: 10917986
You can also fire up SQL profiler and capture the sql statements (if you log them to a table, you can run queries on the table to find certain statements).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

752 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