ADO.NET way for creating a linked table

旧城冷巷雨未停 提交于 2019-12-09 00:57:13

问题


I'm writing an application that uses ADO.NET OLEDB provider. Database is Access. Most of DB interaction is through DDL/DML SQL queries.

I now need to create linked tables and there doesn't seem to be a way of doing that with ADO.NET alone. Neither in a simple DDL query, nor with trying to manipulate Access system tables directly.

I'm trying to avoid using ADOX, with the extra reference/dependency in my application. Anyone knows a way around this? Much appreciated.

Here's how I currently create linked tables with ADOX.

using ADOX;

public static void CreateLinkedTable(string sourceDB, string sourceTable, string targetDB, string targetTable)
{
   Catalog cat = new Catalog();
   cat.let_ActiveConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + targetDB);
   Table table = new Table();
   table.Name = targetTable;
   table.let_ParentCatalog(cat);
   table.Properties["Jet OLEDB:Create Link"].Value = true;
   table.Properties["Jet OLEDB:Link Datasource"].Value = sourceDB;
   table.Properties["Jet OLEDB:Remote Table Name"].Value = sourceTable;
   cat.Tables.Append(table);
}

回答1:


There's not a way around the extra dependency. Linked Tables are a propertiary feature of MS ACCESS, and ADO.NET doesn't know how to do what you want it to do. Access would have to expose this through the SQL commands it accepts, and it doesn't, it's exposed to the extent that it is, through VBA. So you can control it from within the Access DB, but not from outside -- from a ADO.NET connection, all you can do is issue SQL statements that it know how to interpret.



来源:https://stackoverflow.com/questions/7461414/ado-net-way-for-creating-a-linked-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!