How to disable access in my program in C #?

I tried to compress my Access 2007 database as follows:

System.Diagnostics.Process.Start(@"C:\Program Files\Microsoft Office\Office12\msaccess.exe",@"c:\Mydb.mdb /compact "); 

In my C # program, and I get this error:

You tried to open a database that has already been opened exclusively by the user on the machine. Try again when the database is available. (Error 3356)

I tried Conn.close() but still getting an error

Thanks in advance.

+4
source share
5 answers

Check your Task Manager to see if access is open. If you do, close these instances and try again.

0
source

Is pooling possible? I’m not quite sure where the connection pool is implemented (I believe that this is just part of the provider, for example, the SQL server, and therefore may not be related to this problem) But it will maintain open connections between the client and server, even if for the connection object set to closed. You can clear the sql server connection pool using conn.ClearPool. What do you use to connect the provider to your database? (OLEDB?) If so, try ReleaseObjectPool ()

+2
source

Maybe something went wrong and you have an additional * .ldb file. Go to where your database is stored:

C: \ Mydb.ldb

If no one is using it, delete the file.

0
source

// edit start

Check out these basic troubleshooting items:

http://office.microsoft.com/en-us/access-help/troubleshoot-compacting-repairing-or-recovering-an-access-file-HP005188316.aspx?queryid=728e1007c19b43bba069cb7f11364f7a&respos=0&CTT=1

Check if any of the above causes the CD to fail!

// Change the end

Check out the following link: http://support.microsoft.com/kb/209207

Use / excl with the code to open it exclusively.

Thus, the code will look like this:

 System.Diagnostics.Process.Start(@"C:\Program Files\Microsoft Office\Office12\msaccess.exe",@"c:\Mydb.mdb /excl /compact "); 

Using the excl option, you will open it exclusively!

Hope this helps!

0
source

The compact and repair way in Access is to compress a new file, delete the original file, and then rename it. You can use the DAO Engine to do the same. As far as I can tell from MS Visual C # 2010 Express, you can set a link to the DAO and use this:

 var MyDBE=new DAO.DBEngine(); MyDBE.CompactDatabase("c:\\docs\\Mybe.mdb", "c:\\docs\\temp.mdb"); 

To prevent the database from being used, you can check if .ldb exists.

Sorry, but I don't know anything about C #, so these notes are very rude.

0
source

All Articles