c# - Why disconnect from a database? -
background info: i'm coding c#, using microsoft sql server databases.
i didn't find on google on subject, i'm asking here: should close connection database after performing query?
i'm torn between 2 solutions (maybe better ones exist...):
either open connection before querying, close right after sql query
or open connection @ start of application, , before each sql query check if connection still , reopen if needed.
in past, used first solution discovered opening new connection can take quite time (especially on vpn connection lan opened through 3g), , slow down application. that's why decided go second solution (in case, connection should if forget time-out) , noticed better performances.
do need close connection @ end of application or can forget it?
yes, should close connection after each sql query. database connection pool handle physical network connection, , keep open you. found opening connection can take time - did find application really doing multiple times?
(i hope real application won't talking directly database on 3g, btw... presumably development purposes...)
Comments
Post a Comment