Change path linked table ms access

1

I have 2 databases that I use to copy them from the server to the user's local machine. Between these two banks I have a linked table, so when I copy to the local machine, I need to update the address of that linked table.

I saw some forums with vb but found nothing with C #, only VBA ...

link

    
asked by anonymous 28.03.2017 / 20:39

1 answer

1
// the following code requires that the project have a COM reference to:
// "Microsoft Office 14.0 Access Database Engine Object Library"

// create the DBEngine object
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();

// open the local database file containing the linked table
Microsoft.Office.Interop.Access.Dao.Database db = dbe.OpenDatabase(fileNamePainelGerencialTo);

// create a TableDef object for the linked table we want to update
Microsoft.Office.Interop.Access.Dao.TableDef tbd = db.TableDefs["tblPendencia"];

// update the .Connect property with the full path to the remote database
tbd.Connect = ";DATABASE=" + fileNamePainelGerencialPendenciasTo;

// refresh the table link
tbd.RefreshLink();

// create a TableDef object for the linked table we want to update
tbd = db.TableDefs["tblPendenciaBaixa"];

// update the .Connect property with the full path to the remote database
tbd.Connect = ";DATABASE=" + fileNamePainelGerencialPendenciasTo;

// refresh the table link
tbd.RefreshLink();
    
13.04.2017 / 00:04