简体   繁体   English

连接到具有链接表的远程Access 2003数据库

[英]Connect to remote Access 2003 database which has linked tables

I've got this scenario: I developed a C# application which connect to a mdb file (Access 2003) through OleDBConnection (engine = Microsoft.Jet.OLEDB.4.0). 我有这种情况:我开发了一个C#应用程序,该应用程序通过OleDBConnection(engine = Microsoft.Jet.OLEDB.4.0)连接到mdb文件(Access 2003)。 This mdb file has some linked tables in another mdb file in the same directory. 此mdb文件在同一目录的另一个mdb文件中具有一些链接表。 Everything works perfectly in the local environment, the query retrieves data from linked table even if I connect only the main mdb file. 一切都在本地环境中运行良好,即使我仅连接了主mdb文件,查询也会从链接表中检索数据。 A simplified schema could be: 简化的模式可以是:

my application in the local machine --> C:\\mydir\\main.mdb --> C:\\mydir\\linked_tables.mdb 我在本地计算机上的应用程序-> C:\\ mydir \\ main.mdb-> C:\\ mydir \\ linked_tables.mdb

But this application should work in some host computers of a local network. 但是,该应用程序应该可以在局域网的某些主机上工作。 And the mdb files are stored in a server in a shared directory. mdb文件存储在共享目录中的服务器中。 Well, when the application is running in a host I set the path as follow: 好了,当应用程序在主机中运行时,我将路径设置如下:

\\\\myserver\\mydir\\main.mdb \\\\ myserver \\ mydir \\ main.mdb

The connection works. 连接有效。 The problem happens when I launch a query which tries to get data from linked tables. 当我启动试图从链接表中获取数据的查询时,就会发生问题。 It tries to find the linked table in C:\\mydir\\linked_tables.mdb, but this path is on the server, not in the host. 它尝试在C:\\ mydir \\ linked_tables.mdb中查找链接表,但是此路径在服务器上,而不在主机上。

Is there a way to tell him: if the path of the main mdb file is \\\\myserver\\mydir\\main.mdb you must (automatically) get the linked tables on \\\\myserver\\mydir\\linked_tables.mdb? 有没有办法告诉他:如果主mdb文件的路径是\\\\ myserver \\ mydir \\ main.mdb,您必须(自动)获取\\\\ myserver \\ mydir \\ linked_tables.mdb上的链接表?

Thank you 谢谢

I solved with another connection. 我用另一个连接解决了。 I mean: for each mdb file I use a different OleDBConnection. 我的意思是:对于每个mdb文件,我都使用不同的OleDBConnection。

OleDbConnection MainConn = new OleDbConnection("\\myserver\mydir\main.mdb");
OleDbConnection LinkedTablesConn = new OleDbConnection("\\myserver\mydir\linked_tables.mdb");

Not so elegant, but it works. 不太优雅,但可以。 If I have to do some join of tables located in different databases, I manage them with some generic collection objects. 如果必须对位于不同数据库中的表进行某种联接,则可以使用一些通用集合对象来管理它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM