Shared Data Connection

J

John

Hi

I am trying to create a shared data connection class which other classes can
use so there is only one data connection for the whole app. I am not sure
how to create such a data connection class and also how other classes will
access it. Below is how far I have gone into defining the data connection
class, please tell me what is missing.

Thanks

Regards

Public Class clsDataConnection
Shared WithEvents dbConnection As System.Data.OleDb.OleDbConnection

Public Sub New()
Connectdb()
End Sub

Private Sub Connectdb()
Dim dbFile As String

dbFile = "C:\Data\contacts.mdb"

dbConnection = New System.Data.OleDb.OleDbConnection
dbConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source="
& _
dbFile & ";Mode=Share Deny None;Extended Properties="""";Jet OLED" & _
"B:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database
Password="""";J" & _
"et OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global
Partia" & _
"l Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database
Passwor" & _
"d="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt
Database=False;Jet" & _
" OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica Repa" & _
"ir=False;Jet OLEDB:SFP=False"

End Sub

End Class
 
M

Miha Markic

Hi John,

The best approach is to open (and create) a connection immediately before
you need it and close it asap.
Thus, only sharing connection string is prefered and not an entire object.
 

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