您可以使用Office互操作,並獲得信息(文章blatently被盜):
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;
}
}
編輯:
另一種方法是叔o使用DAO(從這個link翻譯日語)。您可能需要調整這些值,但它看起來是一個開始的好地方。
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;
}
您不能從Connection對象讀取它嗎? – 2010-05-24 20:29:53
你真的更新Access 97或以前的數據庫嗎?任何來自Access 2000的將使用Jet 4.0。 – Thomas 2010-05-29 16:24:17
Jet 4支持A97的向後兼容性。也就是說,您可以使用Jet 4來更新Jet 3.x數據庫 - 無需爲此使用Jet 3.x。 – 2010-05-30 19:22:59