In my application to connect to Orace database I always create a new connection, open it, execute OracleCommands and finally close it afterwards. Recently I thought implementing a static connection would be a better idea. Say I have a static connection that I can access from anywhere. Each time I need to connect to database I can check for the state of my static connection,open it if it’s not already open and close it afterwards. Do you think this would be beneficial or there are more disadvantages?
Share
I’m assuming you’re using ODBC here because you haven’t stated exactly and it’s normally used…
No, you should use a new connection each time, this is the standard practise that Microsoft recommend. If you’re using ODBC etc then windows manages these connections, caching them for re-use and it makes it easier to manage the lifetime of things.
If you use a static connection, you might dispose of it to early or have closed it without knowing. In general it’s just a bit more awkward and a premature optimization.
See OdbcConnection for more info.