check existing connections to a .MDB file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, how do i check if other applications is already connected to an access database (.mdb file)? Let's say I have an application that opens an mdb file, for example - test.mdb. Then I opened another instance of the same application and it will also connect to the same mdb file, in this case - test.mdb. What i want is for the application to detect/check/filter that another application is connected to the .mdb file, thus preventing the second instance of the application from connecting to the same file

Thanks in advance :)
 
Open the connection in exclusive mode (Mode=Share Exclusive in the
connection string) and the second connection will fail, so you catch it in a
Try-Catch block.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
ed said:
Hi, how do i check if other applications is already connected to an access
database (.mdb file)? Let's say I have an application that opens an mdb
file, for example - test.mdb. Then I opened another instance of the same
application and it will also connect to the same mdb file, in this case -
test.mdb. What i want is for the application to detect/check/filter that
another application is connected to the .mdb file, thus preventing the
second instance of the application from connecting to the same file.
 
Hi Ed,

As a minor addition to CT.

Normally it is good sence to close connections everytime you have filled a
dataset.
For a access database it is better to open it at the start and at the end of
the program.

Cor
 
Hi Ct

I tried your suggestion (Mode=Share Exclusive) but it didn't work. I was still able to open the MDB file successfully from the two applications.

I'm just working on a connections string made by someone else and it looks like this

'start strin
Public Const gstrCon1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
& "Password="""";User ID=Admin;Data Source=c:\test.mdb
Public Const gstrCon2 As String = ";"
& "Mode=Share Exclusive;Extended Properties="""";Jet OLEDB:System database="""";"
& "Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;"
& "Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;"
& "Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";"
& "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 Repair=False;"
& "Jet OLEDB:SFP=False

conNew = New OleDb.OleDbConnection(gstrCon1 & gstrCon2
conNew.Open(

'end strin

Given that connection string, do you see anything strange? The initial value of Mode before i changed it to "Share Exclusive" is "Share Deny None". I have yet to research on these properties but you guys might have a quick answer so that would really be great

Thanks again :
 
Back
Top