且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保存用于从MS Access 2007到MS SQL Server的ODBC连接的密码

更新时间:2022-11-27 21:04:00

***的解决方案显然是使用Windows安全性.

The best solution is obviously to use Windows security.

如果不合适,这是一个可能的替代技巧,它利用Access会记住所有打开的连接直到程序关闭的事实:

If that is not suitable, here is a possible alternative trick, exploiting the fact that Access remembers all opened connections until the program is closed:

  1. 复制其中一个表的连接字符串
  2. 创建一个通过查询"ptqConnect"并在其中输入任何快速SQL语句,例如SELECT 1
  3. 将连接字符串粘贴到PTQ Connect属性中,并确保在其中添加PWD=something;.
  4. 在应用程序的启动过程中,请确保调用该PTQ.像DCount("*", "ptqConnect")这样的东西.
  1. copy the connect string of one of your tables
  2. create a passthru queries "ptqConnect" and enter any fast SQL statement in it, like SELECT 1
  3. paste the connect string of into the PTQ Connect property, and make sure you add the PWD=something; in it.
  4. in the startup procedure of your app make sure you call that PTQ. Something like DCount("*", "ptqConnect") will do.

就是这样.由于Access在关闭前会记住打开的连接,因此即使关闭数据库,即使链接表的连接字符串中未存储密码,其他表也将立即打开,而不必担心. 如果您不想公开包含PWD的连接字符串,则***通过VBA发起连接并通过提供MDE或仅通过密码保护代码来隐藏代码.

That's it. Since Access remembers opened connections until you close it, even if you close the db, your other tables will now open without any fuss, even if no password is stored in the linked tables Connect string.
If you don't want to expose the connection string that includes the PWD, you could as well initiate a connection from VBA and hide the code by delivering a MDE or just password protecting the code.

您可以找到有关此行为的说明此处.

You can find an explanation of this behaviour here.