By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

check existing connections to a .MDB file

P: n/a
ed
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 :)
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
CT
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" <an*******@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
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 :)

Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

P: n/a
CT
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 :

Nov 20 '05 #4

P: n/a
ed
oops sorry, made a mistake on the display name.
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.