zoukankan      html  css  js  c++  java
  • 在C#中压缩access MDB文件 (转载)

    需要在工程中引用COM组件: Microsoft Jet and Replication Objects Library ,示例请参考下面的函数:

    public static bool CompactJetDatabase(string fileName)
            {
                // I use this function as part of an AJAX page, so rather than throwing
                // exceptions if errors are encountered, I simply return false and allow the page
                // to handle the failure generically.
                try
                {
                    if (fileName.Equals(""))
                        return false;

                    string oldFileName = fileName;

                    // 创建一个生成后的临时文件
                    string newFileName = Path.Combine(Path.GetDirectoryName(oldFileName), Guid.NewGuid().ToString("N") + ".mdb");

                    // 创建压缩类
                    JetEngineClass engine = new JetEngineClass();
                                // 压缩MDB为新的文件
                    engine.CompactDatabase(
                     String.Format(AccessOleDbConnectionStringFormat, oldFileName),
                     String.Format(AccessOleDbConnectionStringFormat, newFileName));

                    // 删除旧文件
                    File.Delete(oldFileName);

                    // 改名为旧文件名.
                    File.Move(newFileName, oldFileName);

                    return true;
                }
                catch (Exception ex)
                {

                    return false;
                }
            }


    原文出处:
    http://www.codeproject.com/useritems/CompactAndRepair.asp

  • 相关阅读:
    Java实现 LeetCode 740 删除与获得点数(递推 || 动态规划?打家劫舍Ⅳ)
    Python oct() 函数
    Python hex() 函数
    Python ord() 函数
    Python unichr() 函数
    Python chr() 函数
    arm,asic,dsp,fpga,mcu,soc各自的特点
    摄像头标定技术
    自主泊车技术分析
    畸变的单目摄像机标定
  • 原文地址:https://www.cnblogs.com/margiex/p/683542.html
Copyright © 2011-2022 走看看