Can I store connection in Application variable?

G

GS

I have system wide connection string defined in web.config. Is it possible to store connection object in global variable accessible by whole application and get reference to it in different parts of code instead of creating new connection each time? How will this survive thread switching?
 
G

Guest

Boy! It just seems like there is a flood of this type of Connection - related
stuff lately!

DON'T Store Connection objects in Application state!

You can store the Connection STRING there, that's fine. Open a new
connection with this connection string just before you need to use it
anywhere in your code, and CLOSE the connection as soon as you can and allow
it to go back to the Connection Pool.

It's that simple. ADO.NET will take care of the rest.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top