Nick3
Nick3

Reputation: 639

Access db, check if someone is using... (OLEDB/C#)

I have a problem with a threaded Client/Server application, I have a serversid that has a Access DB, and with one thread for each client, but I get a problem if both client threads asks to open the DB at the same time. Is there any way to check if the DB is in use (I know I can have a varible and keep controlling/setting that, but would like to avoid that. Here is an example connection

String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + dbPath + "'"; OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command;

connection.Open();
command = new OleDbCommand("UPDATE Client SET Online = " + online)
command.ExecuteNonQuery();
connection.Close();

Would really like some help!

/Nick

Upvotes: 0

Views: 1700

Answers (1)

Dewfy
Dewfy

Reputation: 23614

Per this http://www.connectionstrings.com/access-2007 you can set Exclusive=1 in connection string to grant that only one connection can use this database. All another trying will fail.

Upvotes: 1

Related Questions