Jake
Jake

Reputation: 11430

Single user database connection best practices

With MS Access single user,

Is it good practice or okay to maintain a persistent connection throughout?

psuedocode:

app.start();
access.connect();
domanymanystuff();
access.disconnect();
app.exit();

--- OR ----

app.start();
access.connect();
doonetask();
access.disconnect();
...
access.connect();
doanothertask();
access.disconnect();
...
app.exit();

?

Upvotes: 1

Views: 622

Answers (2)

Agile Jedi
Agile Jedi

Reputation: 2942

Honestly it won't matter since most data connection are pooled and will hang around for reuse after you have closed them. You do want to make sure that your transactions are performed in a 'per unit of work' fashion.

Otherwise, even with a single user DB you could find your application locking itself out.

So, try this:

Open connection
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...    
Start transaction
Perform unit of work
Commit transaction
...
Close connection

Upvotes: 1

Tim
Tim

Reputation: 5421

You can maintain a persistent connection throughout with a single-user database.

Upvotes: 0

Related Questions