修復以及壓縮 Accress 資料庫使用 C#
原理是叫用一JETEngine,用他的方法去壓縮ACCESS資料庫
但是會產生額外的檔案(合理)
所以要再把產生的檔案複製回來即可
引用出處
http://www.cnblogs.com/maxianghui/archive/2006/08/20/481886.html
但是會產生額外的檔案(合理)
所以要再把產生的檔案複製回來即可
object[] oParams; //create an inctance of a Jet Replication Object object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
//filling Parameters array //cnahge "Jet OLEDB:Engine Type=5" to an appropriate value // or leave it as is if you db is JET4X format (access 2000,2002) //(yes, jetengine5 is for JET4X, no misprint here) oParams = new object[] { "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=My.mdb;Persist Security Info=True;Jet OLEDB:Database Password=OnlyYouOnlyYou", ,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"}; //invoke a CompactDatabase method of a JRO object //pass Parameters array objJRO.GetType().InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, null, objJRO, oParams); //database is compacted now //to a new file C:\\tempdb.mdw //let's copy it over an old one and delete it File.Delete(mdwfilename); File.Move("C:\\tempdb.mdb", mdwfilename); //clean up (just in case)
if(objJRO != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO); objJRO = null;
//filling Parameters array //cnahge "Jet OLEDB:Engine Type=5" to an appropriate value // or leave it as is if you db is JET4X format (access 2000,2002) //(yes, jetengine5 is for JET4X, no misprint here) oParams = new object[] { "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=My.mdb;Persist Security Info=True;Jet OLEDB:Database Password=OnlyYouOnlyYou", ,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"}; //invoke a CompactDatabase method of a JRO object //pass Parameters array objJRO.GetType().InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, null, objJRO, oParams); //database is compacted now //to a new file C:\\tempdb.mdw //let's copy it over an old one and delete it File.Delete(mdwfilename); File.Move("C:\\tempdb.mdb", mdwfilename); //clean up (just in case)
if(objJRO != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO); objJRO = null;
引用出處
http://www.cnblogs.com/maxianghui/archive/2006/08/20/481886.html
留言