How to create a Microsoft Jet database (Access) without interoperability assembly?

I need to create an access database (mdb) without using the ADOX interop assembly.

How can I do that?

+5
source share
5 answers

Before throwing this code away, it can also work in stackoverflow

Something in these lines looks like a trick:

if (!File.Exists(DB_FILENAME))
{
    var cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_FILENAME;

    // Use a late bound COM object to create a new catalog. This is so we avoid an interop assembly. 
    var catType = Type.GetTypeFromProgID("ADOX.Catalog");
    object o = Activator.CreateInstance(catType);
    catType.InvokeMember("Create", BindingFlags.InvokeMethod, null, o, new object[] {cnnStr});

    OleDbConnection cnn = new OleDbConnection(cnnStr);
    cnn.Open();
    var cmd = cnn.CreateCommand();
    cmd.CommandText = "CREATE TABLE VideoPosition (filename TEXT , pos LONG)";
    cmd.ExecuteNonQuery();

}

This code shows that you can access the database using OleDbConnection after creating it using the ADOX.Catalog COM component.

+10
source

, Autsin, db Access, . , , . , .

- , , , .

+1

Jet ( ), .net 3.5

Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\myFolder\myAccess2007file.accdb;Persist
Security Info=False;

2007

0

- , . , .

0
source

ACE is not in any structure (but not in 1, 2, 3.5, 4, 4.5)

It is also not part of Windows Update.

JET4 - in Framework2 and higher.

If you are working with Access / MDB files, etc., then do not assume that ACE is present.

0
source

All Articles