|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Remote IDbConnections, opening/closing and errorsIm newish with databases so I'd thought I'd ask a general question. Im using a remote MySQL database accessed across the internet with dotnet provider components. The code I've written creates a new connection for each transaction on the database then closes it again afterwards. So there are many Connection.open/close during the lifetime of my application. I'm wondering if I should be doing this or if I should only open the connection when my database wrapper object is instantiated and close it when it is destroyed. The reason I did it this way was because I was worried about loss of network after the connection was opened. I've no idea about what possible errors this would cause and also how to write nice error handling for a constantly opened connection that dies during the objects lifetime. I also don't know what performance hits that constant opening and closing would cause. I would appreciate that someone with experience please advise me about how to handle this. thanks Claire Keeping a connection open only while you need it is the proper way to go.
Doing otherwise (one connection open for the lifetime of your db wrapper) would just hoard much needed resources on your server. Opening and closing your connections continually isn't going to be much of a performance hit because your connections are pooled. HTH, Cois Show quote "Chukkalove" <some***@microsoft.com> wrote in message news:u5ywLfypGHA.3324@TK2MSFTNGP05.phx.gbl... > Hi > > Im newish with databases so I'd thought I'd ask a general question. > > Im using a remote MySQL database accessed across the internet with dotnet > provider components. > > The code I've written creates a new connection for each transaction on the > database then closes it again afterwards. So there are many > Connection.open/close during the lifetime of my application. > > I'm wondering if I should be doing this or if I should only open the > connection when my database wrapper object is instantiated and close it > when it is destroyed. > The reason I did it this way was because I was worried about loss of > network after the connection was opened. > I've no idea about what possible errors this would cause and also how to > write nice error handling for a constantly opened connection that dies > during the objects lifetime. > I also don't know what performance hits that constant opening and closing > would cause. > > I would appreciate that someone with experience please advise me about how > to handle this. > > thanks > Claire > Keeping a connection open only while you need it is the proper way to go.
Doing otherwise (one connection open for the lifetime of your db wrapper) would just hoard much needed resources on your server. Opening and closing your connections continually isn't going to be much of a performance hit because your connections are pooled. HTH, Cois Show quote "Chukkalove" <some***@microsoft.com> wrote in message news:u5ywLfypGHA.3324@TK2MSFTNGP05.phx.gbl... > Hi > > Im newish with databases so I'd thought I'd ask a general question. > > Im using a remote MySQL database accessed across the internet with dotnet > provider components. > > The code I've written creates a new connection for each transaction on the > database then closes it again afterwards. So there are many > Connection.open/close during the lifetime of my application. > > I'm wondering if I should be doing this or if I should only open the > connection when my database wrapper object is instantiated and close it > when it is destroyed. > The reason I did it this way was because I was worried about loss of > network after the connection was opened. > I've no idea about what possible errors this would cause and also how to > write nice error handling for a constantly opened connection that dies > during the objects lifetime. > I also don't know what performance hits that constant opening and closing > would cause. > > I would appreciate that someone with experience please advise me about how > to handle this. > > thanks > Claire > |
|||||||||||||||||||||||