I am sure you have developed applications dealing with multiple types of databases like SQL Server, MYSQL, or Oracle. Sometimes it is very convenient to just link the tables in a Micrsoft Access database and work with Microsoft's Jet Oledb provider. I have developed a class using C#, which you can include in your code to make linking and unlinking of tables, a breeze. My class references the COM implementation of: 1. Microsoft ActiveX Data Objects 2.8 Library and 2. Microsoft ADO Ext. 2.8 for DDL and Security. Right now the class supports linking of SQL Server and Microsoft Access database tables, however, you can easily customize the code to add support for other databases. How to include this code in your .Net project: Unzip the entire project and create a reference to MSAccessLinking project in your code. Usage Examples:
// Drop all linked tables from c:\myAccess.mdb
MSAccessLinking.unlinkAllExternalTables(@"c:\myAccess.mdb");
// Drop a linked table called Department from c:\myAccess.mdb
MSAccessLinking.unlinkExternalTable(@"c:\myAccess.mdb","Department");
// Link a MS Access table called Department as MyDepartment to c:\myAccess.mdb
// Department table resides in c:\Source.mdb.

MSAccessLinking.linkMSAccessTable( 
            @"c:\myAccess.mdb",
            "Department",
            "MyDepartment",
            @"c:\Source.mdb");
// Link a MS Access table called Department as MyDepartment to c:\myAccess.mdb
// Department table resides in a password protected MS Access database c:\Source.mdb.

MSAccessLinking.linkMSAccessTable( 
            @"c:\myAccess.mdb",
            "Department",
            "MyDepartment",
            @"c:\Source.mdb",
            "MyPassword");
// Link a SQL Server table called Department as MyDepartment to c:\myAccess.mdb
// using Windows Authentication.
// SQL Server runs on MyServer.
// SQL Server runs as MyInstance 
//     (Supply a zero length string if it is default instance)
// SQL Server database is MyDB.

MSAccessLinking.linkSQLTable(
            @"c:\myAccess.mdb",
            "Department",
            "MyDepartment",
            "MyServer",
            "MyDB",
            "MyInstance");
// Link a SQL Server table called Department as MyDepartment to c:\myAccess.mdb
// using SQL Authentication.
// SQL Server runs on MyServer.
// SQL Server runs as MyInstance 
//     (Supply a zero length string if it is default instance)
// SQL Server database is MyDB.
// SQL Login=MyLogin
// SQL Password=MyPassword

MSAccessLinking.linkSQLTable(
            @"c:\myAccess.mdb",
            "Department",
            "MyDepartment",
            "MyLogin",
            "MyPassword",
            "MyServer",
            "MyDB",
            "MyInstance");
// Link an Oracle table called Department as MyDepartment to c:\myAccess.mdb
// Oracle Instance=MyServer (As defined in tnsnames.ora)
// Oracle User Id=MyUserId
// Oracle Password=MyPassword

string oraLinkTemplate="ODBC;Driver={Microsoft ODBC for Oracle};Server=%DatabaseServer%;UID=%UID%;pwd=%PWD%;";
MSAccessLinking.linkExternalTable(
            @"c:\myAccess.mdb",
            "Department",
            "MyDepartment",
            oraLinkTemplate,
            "MyUserId",
            "MyPassword",
            "MyServer",
            "",
            "",
            "",
            "",
            "");
Download Source Code As usual your comments are greatly appreciated.
4

View comments

About Me
About Me
My Photo
Piscataway, New Jersey, United States
I am an electrical engineer by education and a software developer by profession. I like building electro-mechanical models. I also like grilling and barbecuing with passion. To burn my beer cals, I swim and run. I usually post my DIY projects on: http://www.instructables.com/member/kabira/
Blog Archive
Loading
Dynamic Views theme. Powered by Blogger.