Solved

Session Definition and Use in SQL Server

Posted on 2004-04-24
7
249 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

867 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

16 Experts available now in Live!

Get 1:1 Help Now