开发者

ADO.NET way for creating a linked table

开发者 https://www.devze.com 2023-04-05 21:20 出处:网络
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'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 target开发者_如何学PythonDB, 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);
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号