如何结束 ODBC 连接中文件的 Windows 锁定?

发布于 2024-12-19 22:45:41 字数 463 浏览 2 评论 0原文

我正在使用 Access 从一系列结构相同的 SQLite 3 数据库导入数据。我有一个“Import.db”的系统/用户 DSN。我的 Access DB 已将表链接到 Import.db 中的表。

我的目标是通过链接表将数据导入到 Access 表中,然后删除 Import.db,然后将下一个 SQLite3 DB 复制到同一位置并将其命名为 Import.db,然后继续重复该过程,直到全部导入。

我采用这种方法是因为我不知道如何动态创建 DSN 并为 SQLite3 数据库链接表。 SQL Server,是的,但不是 SQLite3。所以我想,只需使用相同的 DSN,但更改实际文件。

问题是,在打开我的 Access DB 并打开链接表后,Access 在 Import.db 上创建了 Windows 文件锁。所以我无法删除和替换它。相反,我可以导入一个,然后关闭 Access,重新打开 Access,然后重复。没那么热。

建议?

I am using Access to import data from a series of SQLite 3 databases that are all structured the same. I have a system/user DSN for "Import.db". My Access DB has linked tables to those in Import.db.

My goal is to import the data via the linked tables into Access tables, then delete Import.db, then copy the next SQLite3 DB to the same location and call it Import.db, and then keep repeating the process till all are imported.

I took this approach because I don't know how to create DSNs on the fly and link tables for SQLite3 dbs. SQL Server, yes, but not SQLite3. So I thought, just use the same DSN but change the actual file.

The trouble is, after opening my Access DB and opening the linked tables, Access creates a Windows file lock on Import.db. So I can't delete and replace it. Instead, I can import one, then close Access, reopen Access, and repeat. Not so hot.

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断爱 2024-12-26 22:45:41

您可以通过以下方式获取链接表的连接字符串:

Debug.Print CurrentDb.TableDefs("MyLinkedTable").Connect

您现在拥有创建不带链接表导入的查询所需的信息。

你可能会得到这样的结果:

ODBC;DSN=SQLite3;Database=Z:\Docs\Import.db;StepAPI=0;SyncPragma=NORMAL;
NoTXN=0;Timeout=;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;
FKSupport=0;JournalMode=;OEMCP=0;LoadExt=;BigInt=0;

但你可能不需要其中的大部分,所以:

sODBC = "[ODBC;DSN=SQLite3;Database=Z:\Docs\Import.db;]"
''Create table query, but append and update are also easy enough
sSQL = "SELECT * INTO SQLite_Import FROM " & sODBC & ".SQLiteTableNameHere"

CurrentDb.Execute sSQL, dbFailOnError

You can get the connection string of a linked table with:

Debug.Print CurrentDb.TableDefs("MyLinkedTable").Connect

You now have the information you need to create a query that imports without a linked table.

You might get something like this:

ODBC;DSN=SQLite3;Database=Z:\Docs\Import.db;StepAPI=0;SyncPragma=NORMAL;
NoTXN=0;Timeout=;ShortNames=0;LongNames=0;NoCreat=0;NoWCHAR=0;
FKSupport=0;JournalMode=;OEMCP=0;LoadExt=;BigInt=0;

But you probably won't need most of it, so:

sODBC = "[ODBC;DSN=SQLite3;Database=Z:\Docs\Import.db;]"
''Create table query, but append and update are also easy enough
sSQL = "SELECT * INTO SQLite_Import FROM " & sODBC & ".SQLiteTableNameHere"

CurrentDb.Execute sSQL, dbFailOnError
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文