What happen if I use static member in asp.net?

S

Sami Vaaraniemi

Yok said:
Can I create a singleton class and put a SqlConnection in it and keep it
open?

In theory, yes you can. In practice, you should not do this.

If you keep the SqlConnection object around across requests, you will
effectively prevent ADO.NET pooling from doing its job. The recommended
usage pattern with an SqlConnection object is to allocate it, use it and
Close it within the same request.

Another problem with keeping an SqlConnection around in a static member is
that the instance members of SqlConnection are not guaranteed to be thread
safe.

In short, not a good idea.

Sami
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top