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:
Right-click on the file, nzoledb. dll, and select Properties. The version number is displayed either in the Product Version field on the Details tab or under the Version tab, depending on your OS. Note: The System32 directory contains either a 32-bit driver (on a 32-bit system) or a 64-bit driver (on a 64-bit system).
Microsoft Access is a database management system (DBMS) from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools.
Microsoft Jet Engine is a database engine on which several Microsoft products have been built. It offers a single interface that other software can use to access Microsoft databases and provides support for security, referential integrity, transaction processing, indexing, record and page locking, and data replication.
Jet allows multiple users to access the database concurrently. To prevent that data from being corrupted or invalidated when multiple users try to edit the same record or page of the database, Jet employs a locking policy.
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)
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With