Solved

Session Definition and Use in SQL Server

Posted on 2004-04-24
7
236 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
Comment Utility
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
Comment Utility
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
Comment Utility
"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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Glass
Comment Utility
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
Comment Utility
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
Comment Utility
Thanxs....  Will look for the identity_insert in my stored procedures.

Glass
0
 
LVL 34

Assisted Solution

by:arbert
arbert earned 125 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to fix this error 14 45
sql server query? 6 26
Sort by Month and Year - SQL 3 22
When to use an Aggregate Function. 18 33
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

744 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

8 Experts available now in Live!

Get 1:1 Help Now