手动关闭ODBC DSN连接 [英] Manually Close ODBC DSN Connection

查看:113
本文介绍了手动关闭ODBC DSN连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MS Access数据库,该数据库通过用户级DNS ODBC数据源连接到另一个数据库.

I have an MS Access database that connects to another database via a user level DNS ODBC data source.

首次启动连接时,ODBC驱动程序将提示我输入用户名和密码.然后服务器上连接到的数据库取决于我使用的用户名.

When the connection is first initiated the ODBC driver will prompt me for a username and password. The database that it then connects to on the server is dependent on the username I use.

建立连接后,Access将保留/保持活动状态,直到我关闭Access数据库为止.

Once the connection is established Access will retain / keep it alive until I close the Access database.

有没有一种方法可以强制Access关闭所有打开的ODBC连接,要求我下次尝试访问服务器上的对象时再次提供登录凭据.我想要做的是切换ODBC连接正在访问哪个数据库,而不必完全关闭Access并重新打开数据库.

Is there a way to force Access to close all open ODBC connections, requiring me to provide the login credentials again when I next try to access an object on the server. What I want to be able to do is switch which database the ODBC connection is accessing without having to completely close Access and re-open the database.

推荐答案

两件事:
1)通过执行以下操作,可以使用户尽可能轻松地关闭和重新打开Access的过程:

Two things:
1) You can make the process of closing and re-opening Access as painless as possible for your users by doing:

' Close and restart
Shell "restart.bat", vbNormalFocus
Application.Quit

with restart.bat由类似

with restart.bat consisting of something like

REM wait for Access to close
TIMEOUT 3
REM your actual command line goes here
msaccess.exe mydatabase.mdb

2)您提到:

我想做的是切换ODBC的数据库 连接正在访问

What I want to be able to do is switch which database the ODBC connection is accessing

您发布的链接给了我一个主意:

The link you posted gave me an idea:

任何随后三个匹配的ODBC对象 参数-ODBC驱动程序,服务器和数据库-将重用已缓存的 连接.

Any subsequent ODBC objects that happen to match on three parameters—ODBC driver, server, and database—will reuse that cached connection.

如果将链接的表从用户DSN切换到无DSN的连接,则所需的行为应自动发生.
只需通过更改"Database = ..."部分来更改所有表的.Connect字符串,下次访问表时,Access会要求提供凭据.

If you switch your linked tables from User DSN to DSN-less connections, your desired behaviour should happen automatically.
Just change the .Connect string of all tables by altering the "Database=..." part, and Access should ask for credentials when a table is accessed the next time.

这篇关于手动关闭ODBC DSN连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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