简体   繁体   English

尝试打开访问97数据库时无法识别的数据库格式

[英]Unrecognized Database Format While trying to open access 97 database

I created a mdb (Access Database 97) file with that code , 我用该代码创建了一个mdb(Access Database 97)文件,

  string DBPath = @"C:\\Users\\Desktop\\test.mdb";

        // create DB via ADOX if not exists
        if (!File.Exists(DBPath))
        {
            ADOX.Catalog cat = new ADOX.Catalog();
            cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DBPath);
            cat = null;
        }

        // connect to DB
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + DBPath);
        con.Open();

When I am trying to open created database it gives an "unrecognized database format" error. 当我尝试打开创建的数据库时,它会出现“无法识别的数据库格式”错误。

I am using Microsoft Access 97 , I guess it is 32 bit. 我使用的是Microsoft Access 97,我猜它是32位。 I tried all platform targets(x86,x64 & Any CPU) from C# but still same problem. 我尝试了来自C#的所有平台目标(x86,x64和任何CPU),但仍然存在同样的问题。

The both access 97 and Microsoft Office 2010 installed in my computer. 我的计算机中安装了访问97和Microsoft Office 2010。

The error is like that; 错误就是这样;

在此输入图像描述

Could you please help me ? 请你帮助我好吗 ?

After conducting deep research in hours, I found 2 main issues regarding database connection: 经过几个小时的深入研究,我发现了两个与数据库连接有关的主要问题:

  1. Using backslash escape sequences in a string literal doesn't converting escape sequence character, instead you should use one backslash for file path: 在字符串文字中使用反斜杠转义序列不会转换转义序列字符,而是应该使用一个反斜杠作为文件路径:

     string DBPath = @"C:\\Users\\Desktop\\test.mdb"; 
  2. The connection string provider to connect with Access database in question uses Microsoft ACE OLE DB 12.0, which only supported by Access 2007 and later with ACCDB format (use Microsoft Jet 4.0 provider instead). 用于连接有问题的Access数据库的连接字符串提供程序使用Microsoft ACE OLE DB 12.0,它仅受Access 2007和更高版本支持ACCDB格式(改为使用Microsoft Jet 4.0提供程序 )。

    Additionally, in database creation part which includes ADOX.Catalog.Create() method, it should include Jet OLEDB:Engine Type parameter to specify which Access version being used. 此外,在包含ADOX.Catalog.Create()方法的数据库创建部分中,它应包括Jet OLEDB:Engine Type参数,以指定正在使用的Access版本。 By default it sets to Jet OLEDB:Engine Type=5 which means Access 2000 file format (will trigger unrecognized database format error in Access 97), hence to force ADOX creating MDB with Access 97 format it is necessary to set Engine Type=4 like below: 默认情况下,它设置为Jet OLEDB:Engine Type=5 ,这意味着Access 2000文件格式(将在Access 97中触发unrecognized database format错误),因此强制ADOX创建具有Access 97格式的MDB,有必要设置Engine Type=4下面:

     // database creation if (!File.Exists(DBPath)) { ADOX.Catalog cat = new ADOX.Catalog(); cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBPath + ";Jet OLEDB:Engine Type=4"); // other stuff } // connect to database using Jet OLE DB provider OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBPath); 

Additional reference: 附加参考:

Unrecognized MDB created by ADOX ADOX创建的无法识别的MDB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM