如何以编程方式确定 Jet 数据库引擎类型

发布于 2024-09-02 12:38:28 字数 479 浏览 5 评论 0原文

我有一个程序需要将其打开的任何 Access (Jet) 数据库升级到 JET Version4.x(如果它还不是该版本)。 (这使得可以使用 SQL-92 语法功能)

升级(相对)容易。对 JRO.JetEngine 对象的 CompactDatabase 方法的调用(如此处所述)应该这样做,但在这样做之前,我需要确定是否需要升级。如何确定现有数据库的 Jet OLEDB:Engine Type?这可以从打开的 OleDBConnection 确定吗?

注意:

  1. 我说的是数据库版本,而不是 Jet 库版本。
  2. 非常感谢 C# 或 .Net 解决方案。
  3. 这是一个使用 Jet 引擎的应用程序,而不是 Access 应用程序。

I have a program which needs to upgrade any Access (Jet) database it opens to JET Version4.x if it isn't already that version. (This enables use of SQL-92 syntax features)

Upgrading is (relatively) easy. A call to the JRO.JetEngine object's CompactDatabase method (as described here) should do the trick, but before I do this I need to determine whether an upgrade is required. How do I determine the Jet OLEDB:Engine Type of an existing database? Can this be determined from an open OleDBConnection?

Note:

  1. I'm talking about database versions, not Jet library versions.
  2. C# or .Net solution greatly appreciated.
  3. This is an application which uses the Jet engine, NOT an Access application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏雨凉 2024-09-09 12:38:28

您必须设置对 ADO 的引用,然后才能获取该属性。

从 Access 内部

Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

从 Access 外部

Dim cnn As New ADODB.Connection
cnn.Open Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Contact.mdb

最后

Debug.Print cnn.Properties("Jet OLEDB:Engine Type").Value

.Value 将返回 1 到 5。如果是5、Jet4x中已经有了,否则就是早期版本。

这是您正在查看的升级技术的另一个示例: 将 MDB 数据库转换为另一种格式 (JET ,访问版本)

You'll have to set a reference to ADO and then you can get the property.

From inside of Access

Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

From outside of Access

Dim cnn As New ADODB.Connection
cnn.Open Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Contact.mdb

And finally

Debug.Print cnn.Properties("Jet OLEDB:Engine Type").Value

This .Value will return 1 to 5. If it is 5, it is already in Jet4x, otherwise it is an earlier version.

Here's another example of the upgrade technique you're looking at as well: Convert MDB database to another format (JET, access version)

恬淡成诗 2024-09-09 12:38:28

您可以使用 Office Interop 并获取信息(公然从文章中窃取):

如何确定创建数据库时使用的是哪个版本的 Access?

    public void WhichVersion(string mdbPath)
    {
        Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.ApplicationClass();
        oAccess.OpenCurrentDatabase(mdbPath, false, "");

        Microsoft.Office.Interop.Access.AcFileFormat fileFormat = oAccess.CurrentProject.FileFormat;

        switch (fileFormat)
        {
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2:
                Console.WriteLine("Microsoft Access 2"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess95:
                Console.WriteLine("Microsoft Access 95"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess97:
                Console.WriteLine("Microsoft Access 97"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2000:
                Console.WriteLine("Microsoft Access 2000"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2002:
                Console.WriteLine("Microsoft Access 2003"); break;
        }

        oAccess.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone);
        Marshal.ReleaseComObject(oAccess);
        oAccess = null;
    }
}

编辑:

另一种方法是使用 DAO(来自此 链接,翻译自日语)。您可能需要调整这些值,但这看起来是一个不错的起点。

public int GetCreatedVersion(string mdbPath)
{
    dao.DBEngine engine = new dao.DBEngine();
    dao.Database db = engine.OpenDatabase(mdbPath, false, false, "");
    string versionString = db.Properties["AccessVersion"].Value.ToString();
    int version = 0;
    int projVer = 0;

    switch (versionString.Substring(0, 2))
    {
        case "02":
            version = 2; break;
        case "06":
            version = 7; break;
        case "07":
            version = 8; break;
        case "08":
            foreach (dao.Property prop in db.Properties)
            {
                if (prop.Name == "ProjVer")
                {
                    projVer = int.Parse(prop.Value.ToString());
                    break;
                }
            }
            switch (projVer)
            {
                case 0:
                    version = 9; break;
                case 24:
                    version = 10; break;
                case 35:
                    version = 11; break;
                default:
                    version = -1; break;                            
            }
            break;
        case "09":
            foreach (dao.Property prop in db.Properties)
            {
                if (prop.Name == "ProjVer")
                {
                    projVer = int.Parse(prop.Value.ToString());
                    break;
                }
            }
            switch (projVer)
            {
                case 0:
                    version = 10; break;
                case 24:
                    version = 10; break;
                case 35:
                    version = 11; break;
                default:
                    version = -1; break;
            }
            break;
    }
    db.Close();

    return version;
}

You can use Office Interop and get the info (blatently stolen from the article):

How Can I Determine Which Version of Access was Used to Create a Database?

    public void WhichVersion(string mdbPath)
    {
        Microsoft.Office.Interop.Access.Application oAccess = new Microsoft.Office.Interop.Access.ApplicationClass();
        oAccess.OpenCurrentDatabase(mdbPath, false, "");

        Microsoft.Office.Interop.Access.AcFileFormat fileFormat = oAccess.CurrentProject.FileFormat;

        switch (fileFormat)
        {
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2:
                Console.WriteLine("Microsoft Access 2"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess95:
                Console.WriteLine("Microsoft Access 95"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess97:
                Console.WriteLine("Microsoft Access 97"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2000:
                Console.WriteLine("Microsoft Access 2000"); break;
            case Microsoft.Office.Interop.Access.AcFileFormat.acFileFormatAccess2002:
                Console.WriteLine("Microsoft Access 2003"); break;
        }

        oAccess.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveNone);
        Marshal.ReleaseComObject(oAccess);
        oAccess = null;
    }
}

EDIT:

Another method is to use DAO (from this link translated from Japanese). You may have to tweak the values, but it looks like a good place to start.

public int GetCreatedVersion(string mdbPath)
{
    dao.DBEngine engine = new dao.DBEngine();
    dao.Database db = engine.OpenDatabase(mdbPath, false, false, "");
    string versionString = db.Properties["AccessVersion"].Value.ToString();
    int version = 0;
    int projVer = 0;

    switch (versionString.Substring(0, 2))
    {
        case "02":
            version = 2; break;
        case "06":
            version = 7; break;
        case "07":
            version = 8; break;
        case "08":
            foreach (dao.Property prop in db.Properties)
            {
                if (prop.Name == "ProjVer")
                {
                    projVer = int.Parse(prop.Value.ToString());
                    break;
                }
            }
            switch (projVer)
            {
                case 0:
                    version = 9; break;
                case 24:
                    version = 10; break;
                case 35:
                    version = 11; break;
                default:
                    version = -1; break;                            
            }
            break;
        case "09":
            foreach (dao.Property prop in db.Properties)
            {
                if (prop.Name == "ProjVer")
                {
                    projVer = int.Parse(prop.Value.ToString());
                    break;
                }
            }
            switch (projVer)
            {
                case 0:
                    version = 10; break;
                case 24:
                    version = 10; break;
                case 35:
                    version = 11; break;
                default:
                    version = -1; break;
            }
            break;
    }
    db.Close();

    return version;
}
幸福丶如此 2024-09-09 12:38:28

只需对使用 SQL-92 语言功能的语句进行测试调用即可。如果失败,则需要升级。

Just make a test call of a statement which uses SQL-92 language features. If it fails, you need to upgrade.

野稚 2024-09-09 12:38:28

我知道这是一篇旧帖子,但我已经寻找了几天来找到可以检索的其他属性列表,例如“Jet OLEDB:引擎类型”。这是一个 MS 链接,其中列出了所有属性。
Jet 提供商特定连接参数列表

I know this an old post but I've looked for days to find a list of other properties that can be retrieved like the "Jet OLEDB:Engine Type". Here's a MS link with all the properties listed.
Jet Provider Specific Connection Parameters Listing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文