In a C# application, should a DB Connection be created once, or everytime a SQL statement is executed?

Spread the love

Question Description

In a C# application, should a OleDBConnection be created once, or every time a SQL statement is executed?

I am looking at C# code written by someone else. Every SQL statement is preceded with the creation of an OleDbConnection object whose connection string points to an MDB database.

Is it appropriate to create an OleDbConnection object every time, or should the object be created at the start of the application and used from then on.

Practice As Follows

According to Best Practices for Using ADO.NET:

High performance applications keep
connections to the data source in use
for a minimal amount of time, as well
as take advantage of performance
enhancing technology such as
connection pooling…

Leave a Comment