ADO.NET 创建链接表的方式 [英] ADO.NET way for creating a linked table

查看:19
本文介绍了ADO.NET 创建链接表的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用 ADO.NET OLEDB 提供程序的应用程序.数据库是Access.大多数数据库交互是通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆