sqlite static database connection over multiple instances

D

Digital Fart

hi

I want to wrap the access to a sqlite database in an object. So i can
create multiple instances of this wrapper with base code to get data
out of the sqlite database.

But i want to make the connection only onces when i create the first
instance. And when the program ends the connection should be removed.

ex.

wrapper objects

query wrapperQuery1 = new query(); // here the database should connect
query wrapperQuery2 = new query(); // connection should already exists
query wrapperQuery3 = new query(); // connection should already exists

wrapperQuery1.close(); // dbconnect stays open
wrapperQuery3.close(); // dbconnect stays open
wrapperQuery2.close(); // dbconnect should close now when.

How would i contruct this?
 
N

Nicholas Paldino [.NET/C# MVP]

Digital Fart,

That's a REALLY bad way of handling this. Basically, when you perform
your query, you should open the connection, perform the operation, and close
it.

Database connections are the kind of resources that degrade over time,
and also are limited in use (if you have one being sucked up, that's one
less connection that can be made to the database).

My advise is to open the connection and close it when you are done with
the query.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top