Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Session Definition and Use in SQL Server

Posted on 2004-04-24
7
Medium Priority
?
287 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
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!

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

721 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