c# - Create Access 97 database without dependency on Access -
For compatibility with legacy software, I need to create an .mdb database compatible with Access 97 or earlier versions. I can not use OLDB because I can not trust access to set up. I also do not want to install office connectivity components.
Are there any third party libraries that can do this?
Jet part of the Windows interface forever (as part of the MDAC component from Windows 2000) No need to access the .mdb
file for
You only need to install ACE drivers if you plan to create new .accdb
files (compatible with Access 2007 and above).
To create an empty .mdb
database, you need to use the Microsoft ADO Ext 2. Datab and security for the 2.8 library Interop.ADOX. Dll
.
You can call it your VS. There is no need to referencing directly in the project, you can use late binding to create the object that is available on the machine:
zero main () {var conStr = GetConnectionString (@ "C: \ Users \ user \ Desktop \ myDatabase.mdb", blank, zero); CreateDb (Construction); } //[System.Security.SecuritySafeCritical] Public Zero CreateDb (string connection string) {type adoxType = Type.GetTypeFromProgID ("ADOX.Catalog"); Object O = Activator Create Instances (Adox Type); O.GetType () InvokeMember ("Create", BindingFlag.Invokmath, Blank, O, New Object [] (connectionString)); Object connection = o.GetType (). InvokeMember ("ActiveConnection", BindingFlags.GetProperty, null, o, null); If (connection! = Zero) connection Gettype () InvokeMember ("Close", Binding Falgues, Invocomath, Blank, Connection, Blank); } Public static string GetConnectionString (string database, string user id, string password) {return string.format (" 1}; {3} Password = {2}; ", Database, UserAd, Password, String.IsNellOcty (password)? String:" Jet Olendi: Database "); }
You can use LINQpad to test the code, it works on my machine Note that if you try to create a database in folders, where you have If you do not have the rights to create files, then you will get an unrelated COM exception such as:
The Microsoft Jet database engine can not open the file 'C: \ myDatabase.mdb' This is already done by another user Has been opened, or you see its data Area requires permission.
To create tables and indexes etc., you can use these commands and execute them through OLEDB, such as command.execute nonquiries ("Create table staff CRAR, LastName CRAR) ");
Another, perhaps this simple solution that can be avoided all this code,
to open the database, you can only use OldDb as the old one .
To be careful about things: Make sure you target X86 for your app;
Comments
Post a Comment