Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Session Definition and Use in SQL Server

Posted on 2004-04-24
7
Medium Priority
?
291 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 500 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 500 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

783 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