开发者

how to disconnection access in my C# program?

I tried to compress my Access 2007 database like this:

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

In my C# program and I get this error:

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

I tried Conn.close() but still get the error

Thanks in advance.


Maybe connection pooling is the issue? Not completely sure where connection pooling is implemented (I believe that this is just part of the provider e.g. SQL server and therefore might not be relevant to this issue) But it will keep connections open between the client and server even thougth the connection object is set to "closed". You can clear a sql server connection pool using conn.ClearPool What are you using for the provider to connect to your database? (OLEDB?) If so try ReleaseObjectPool()


Check your Task Manager to see if you have Access already open. If you do, close these instances and retry.


Maybe something went wrong and you just have an extra *.ldb file out there. Go to where your DB is stored:

c:\Mydb.ldb

If no one is using it delete the file.


The way compact & repair works in Access is it compacts to a new file, deletes the original file and then renames. You can use the DAO Engine to do the same thing. As far as I can tell from MS Visual C# 2010 Express, you can set a reference to DAO and use that:

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

To ensure the database is not in use, you can check if the .ldb exists.

I am sorry, but I do not know anything about c#, so these notes are very crude.


//Edit begin

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

See if any of the above reasons are causing the compact to fail!

//Edit end

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

Use /excl with the code to open it exclusively.

So code would be:

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

By using the excl option you will be opening it exclusively!

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜