【问题标题】:OleDb conflicts with Windows 7 running MS Office 2007OleDb 与运行 MS Office 2007 的 Windows 7 冲突
【发布时间】:2013-04-15 22:05:02
【问题描述】:

该程序在运行 MS Office 2007 的 Windows XP 中完美运行,但在运行 MS Office 2007 的 Windows 7 中无法运行。所以我决定使用 Microsoft.Ace,所以我使用了这个连接字符串:

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
    + "Data Source=\"" + strDir + "\\\";"
    + "Extended Properties=\"text;HDR=YES;IMEX=1\"";

这是方法:

public DataTable Load(string path, int columnCount)
{
    CreateSchema(path, columnCount);
    DataTable dtData = new DataTable();

    string fullPath = Path.GetFullPath(path);
    string csvFile = Path.GetFileName(fullPath);
    string directoryName = Path.GetDirectoryName(fullPath);

    string query;

    string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
      + "Data Source=\"" + directoryName + "\\\";"
      + "Extended Properties=\"text;HDR=YES;IMEX=1\"";

    query = "SELECT * FROM " + csvFile;

    OleDbDataAdapter dtAdapter = new OleDbDataAdapter(query, connString);

    dtAdapter.Fill(dtData);

    dtAdapter.Dispose();

    return dtData;
}

我的主要问题是,当我使用此连接字符串时,程序在运行 MS Office 2007 的 Windows XP 中运行,但在运行 MS Office 2007 的 Windows 7 中运行:

string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
    + "Data Source=\"" + strDir + "\\\";"
    + "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";

我的研究表明我需要使用 ACE,所以我使用了这个 connectionString:

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
    + "Data Source=\"" + strDir + "\\\";"
    + "Extended Properties=\"text;HDR=YES;IMEX=1\"";

但仍然没有帮助。请帮我!谢谢!

【问题讨论】:

    标签: c# .net oledb


    【解决方案1】:

    这两个连接字符串用于不同类型的文件。
    第一个用于文本文件,第二个用于 Excel 2007

    第一个使用目录名作为DataSource,
    第二个需要一个 Excel 文件的名称作为strDir 的输入

    connectionstrings for Excel2007connectionstrings for Text Files

    这可能是您现在在 ACE 上遇到的错误的根源。
    关于 XP 上的错误,我只能假设这与缺少 JET/ACE 驱动程序有关。在这种情况下,问题出在您为其编译应用程序的平台上。请看this question and related answer

    【讨论】:

    • 我在这里看到你的答案stackoverflow.com/questions/11078675/…,这也是我的问题吗?
    • 是的,这是可能的,但在不知道您确切的错误信息的情况下,无法确定。请发布收到的错误消息
    • 这是异常get: microsoft.ace.oledb.12.0 provider is not registered on local
    • 是的,这就是确切的症状。为 AnyCPU 编译的应用程序试图在 64 位操作系统上加载 32 位驱动程序,或者您的代码、操作系统和驱动程序之间存在其他不匹配
    • 谢谢,我将构建到 x86 并在我客户的 PC 上试用
    猜你喜欢
    • 2016-12-27
    • 2010-09-08
    • 2010-11-22
    • 2010-12-29
    • 1970-01-01
    • 2012-02-04
    • 2011-05-28
    • 2011-02-06
    • 1970-01-01
    相关资源
    最近更新 更多