Avatar of amitant
amitant asked on

Local SQL DB

Hi

I have a .NET project that runs on several machines and uses SQL server
On one development machine that doesnt have an SQL server, i want to use an mdf file as an SQL server. I ping the SQL 'server' approx every second. I see that the opening of the connection might last for several seconds.
is it normal?
should i keep the connection open?
what are the best practices to do it?

thanks
.NET ProgrammingEditors IDEsMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
amitant

8/22/2022 - Mon
hasander

It is expensive to open and close connections. The best solution is to use connection pooling. When you "close" your connection it is returned to the connection pool.
ASKER
amitant

isnt the pooling performed automatically by the .NET framework?
I once used the pooling by always opening commections (SqlConnection.Open()) but than i got a 'too many open Connections' Exception. So i dont know wether to close the connections after I use them.

This is my current sql access pattern:
conn.open
executeQuery
conn.close

should i remove the 'conn.close' ?

thanks
hasander

I think you have to specify connection pooling in your connection string.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
amitant

i already used min number of connections=1 in the connstring,
does that mean that after conn.Close The connection is still 'open' in the pool but free to be used again by the application?
ASKER CERTIFIED SOLUTION
hasander

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
amitant

it seems to be ok now
thanks