2

I am trying to run a query on an access database located on a distant server (my code is written in C#). I use the following code and connection string:

public static string MadoneConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= {0}; Persist Security Info = False; User ID = {1}; Password ={2};";

string ConnectionString = string.Format(Constants.MadoneConnectionString, DatabasePath, userId, password);

using (OleDbConnection cnn = new OleDbConnection(ConnectionString))
            {
                //..my code..//
                int count = 0;
                using (OleDbCommand cmd = new OleDbCommand(query, cnn))
                {
                    cnn.Open();
                    using (OleDbDataReader reader = cmd.ExecuteReader())
                    {
                        // my code //
                    }
                }
            }

When I run the code I have the error in the title:

Can not start your application The workgroup information file is absent or opened exclusively by another user.

I tried to do as suggested here, and added this

Jet OLEDB:System Database=system.mdw;

to connection string,

but I had a message saying that login or password is wrong.

Did somebody encounter the same error? How did you solve it?

Thanks

mStudent
  • 1,568
  • 3
  • 15
  • 21
  • Do you or anyone else have the database open in access? – Tom Dee Jul 20 '18 at 09:52
  • I don't, but maybe someone else does, as the database is shared. – mStudent Jul 20 '18 at 09:54
  • I would put my money on that being the problem, try making a copy of the database locally and connecting to that – Tom Dee Jul 20 '18 at 09:55
  • Access is really not a good choice for a data source like this. Your going to need to use a proper DBMS like SQL Server or MySQL – Liam Jul 20 '18 at 10:06
  • Seems you should also [confirm you connection string is correct](https://stackoverflow.com/a/2458782/542251) – Liam Jul 20 '18 at 10:09
  • Thanks Tom, but the base is huge and updated daily so I can't make a local copy for the wished use. Thanks too Liam, I checked that and it seems the connection string I am using is correct, apart from Jet OLEDB:System parameter which does not work on my side – mStudent Jul 20 '18 at 13:18
  • @the_drug I meant just create a copy of the database and try to connect to it, this way you can narrow down if other users are causing the lock. If that is indeed the problem, then you can work out a solution from that. – Tom Dee Jul 20 '18 at 13:38
  • @Liam - what information do you have that prompts you to suggest those database alternatives as being better than Access? – dbmitch Jul 23 '18 at 22:29
  • Adding Jet OLEDB:System Database=system.mdw; to my connection string solved the problem. The login I was trying to use was deactivated, that's why there was an error message saying the login is wrong. Thanks to all for your time. – mStudent Jul 31 '18 at 08:49

3 Answers3

1

This is caused by someone else opening the database file in access which creates a lock. Since you're using using statements in your application, that shouldn't be keeping the connection open so seems unlikely that your code is causing the lock. In my old company this used to happen all the time when ASP pages try to connect to an access database and someone had it open.

The two solutions I can think of are:

  1. Ensure the database cannot be opened by other people, by changing the file location or just telling people not to.

  2. The better solution, have a database server which can support multiple users.

Tom Dee
  • 2,516
  • 4
  • 17
  • 25
  • Thanks Tom, but I don't really have choice, I have to deal with the existing setup. And the Database is shared by many users. I am still trying to find out a solution – mStudent Jul 20 '18 at 13:24
1

This can also be caused by a password in the connection string when the database isn't using a password.

0

Adding

Jet OLEDB:System Database=system.mdw; 

to my connection string solved the problem. The login I was trying to use was deactivated, that's why there was an error message saying the login is wrong. Thanks to all for your time.

mStudent
  • 1,568
  • 3
  • 15
  • 21