ADO.NET创建链接表的方式 [英] ADO.NET way for creating a linked table
问题描述
我正在编写一个使用ADO.NET OLEDB提供程序的应用程序。数据库是访问。大多数数据库交互都是通过DDL / DML SQL查询进行的。
I'm writing an application that uses ADO.NET OLEDB provider. Database is Access. Most of DB interaction is through DDL/DML SQL queries.
我现在需要创建链接表,而且似乎没有一种方法可以单独使用ADO.NET。既不是在简单的DDL查询中,也不是尝试直接操作Access系统表。
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.
我试图避免使用ADOX,因为我的应用程序具有额外的引用/依赖性。有人知道解决这个问题的方法吗?
I'm trying to avoid using ADOX, with the extra reference/dependency in my application. Anyone knows a way around this? Much appreciated.
这是我当前使用ADOX创建链接表的方式。
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);
}
推荐答案
额外的依赖。链接表是MS ACCESS的专有功能,而ADO.NET不知道该怎么做。 Access必须通过它接受的SQL命令来公开它,而不能,而是通过VBA公开它。因此,您可以从Access DB进行控制,而不能从外部进行控制-通过ADO.NET连接,您所能做的就是发出知道如何解释的SQL语句。
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.
这篇关于ADO.NET创建链接表的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!