I built a Windows Service in VB.Net, that works with an Access 2003 database behind the scenes, no user interaction, it monitors the actions of the main computer in our system. We just rebuilt it - making a second Service that handles some logic for sending messages to the maintenance folks if there is a problem. It also has to query the database. Up to now its been fine, but now that there are 2 apps we have seen some kind of conflict or contention for opening connections. None of us is a database expert, we just selected Access as a reasonable answer to our need for a database that would work and wouldnt need too much investment or learning curve.
The code uses System.Data.OleDb for OleDbConnection, OleDbCommand, and OleDbDataReader classes.
I built a little test app that starts a thread that continuously opens, queries, reads, and closes. When I get enough copies of that app running I see the same failures, with Exception.Message text saying one of 3 things:
1. Cannot open database . It may not be a database that your application recognizes, or the file may be corrupt.
2. You attempted to open a database that is already opened exclusively by user Admin on machine DEVELOPER. Try again when the database is available.
3. Could not use ; file already in use.
Someone told me on a forum to make sure that the Access properties were set to default to Open Shared. I discovered that when I open the database in Access while a bunch of my little test apps are running and failing, the failures stop. I believe that there is something in the connection from Access that is telling the database to be available to other connections but when opened from my code its not doing that. I figure that I have to give my OleDbConnection.ConnectionString the right set of properties to make it work in code
Ive found several sites that indicate Connection String properties for Jet OLEDB but cant find one that works. It looks like "Share Deny None" should be the one I want but I cant find the right syntax. Im quite surprised that when I create one from the .Net toolbox and use the GUI to set the settings for it, "Mode=Share Deny None" is what Windows generates for me, but it doesnt work. When I use that in the string, I get "Could not lock file."
Anyone know the .Net code for telling an Access database to open as Shared for all users?
The code uses System.Data.OleDb for OleDbConnection, OleDbCommand, and OleDbDataReader classes.
I built a little test app that starts a thread that continuously opens, queries, reads, and closes. When I get enough copies of that app running I see the same failures, with Exception.Message text saying one of 3 things:
1. Cannot open database . It may not be a database that your application recognizes, or the file may be corrupt.
2. You attempted to open a database that is already opened exclusively by user Admin on machine DEVELOPER. Try again when the database is available.
3. Could not use ; file already in use.
Someone told me on a forum to make sure that the Access properties were set to default to Open Shared. I discovered that when I open the database in Access while a bunch of my little test apps are running and failing, the failures stop. I believe that there is something in the connection from Access that is telling the database to be available to other connections but when opened from my code its not doing that. I figure that I have to give my OleDbConnection.ConnectionString the right set of properties to make it work in code
Ive found several sites that indicate Connection String properties for Jet OLEDB but cant find one that works. It looks like "Share Deny None" should be the one I want but I cant find the right syntax. Im quite surprised that when I create one from the .Net toolbox and use the GUI to set the settings for it, "Mode=Share Deny None" is what Windows generates for me, but it doesnt work. When I use that in the string, I get "Could not lock file."
Anyone know the .Net code for telling an Access database to open as Shared for all users?