G
Guest
I have a windows app that instantiates custom objects from a class library
many times over and over. Each object interacts with the database and must
create, open, and close the database connections as needed. As you can
imagine, this is very inefficient when working with a database.
I would like to create one database connection that is shared among my
objects. Short of sending this connection to each object when I instantiate
them, what can I do to simplify this process to allow all instantiated
objects to use a single database connection?
Example of what I don't want to have to do for every custom object instance:
Dim oDBConnection as new SQLConnection(MyConnectionString)
Dim oMyObject as new MyLibrary.MyObject(oDBConnection)
Example of what I would like to do:
(main forms app)
Protected Shared DBConnection as new SQLConnection(MyConnectionString)
Dim oMyObject as new MyLibrary.MyObject
(inside MyObject new constructor)
Private oConn as SQLConnection
Public Sub New()
' Go get the db connection from the parent calling windows app
oConn = (someblackmagic).DBConnection
End Sub
So, where you see (someblackmagic) I would like to somehow get that
DBConnection from the calling assembly's (windows app) Shared variable
DBConnection.
Any help would be greatly appreciated.
many times over and over. Each object interacts with the database and must
create, open, and close the database connections as needed. As you can
imagine, this is very inefficient when working with a database.
I would like to create one database connection that is shared among my
objects. Short of sending this connection to each object when I instantiate
them, what can I do to simplify this process to allow all instantiated
objects to use a single database connection?
Example of what I don't want to have to do for every custom object instance:
Dim oDBConnection as new SQLConnection(MyConnectionString)
Dim oMyObject as new MyLibrary.MyObject(oDBConnection)
Example of what I would like to do:
(main forms app)
Protected Shared DBConnection as new SQLConnection(MyConnectionString)
Dim oMyObject as new MyLibrary.MyObject
(inside MyObject new constructor)
Private oConn as SQLConnection
Public Sub New()
' Go get the db connection from the parent calling windows app
oConn = (someblackmagic).DBConnection
End Sub
So, where you see (someblackmagic) I would like to somehow get that
DBConnection from the calling assembly's (windows app) Shared variable
DBConnection.
Any help would be greatly appreciated.