2025年9月17日 星期三

VB6 + ODBC + Access MDB: Setup Tricks

1️⃣ ODBCAD32 (64-bit) vs ODBCAD32 (32-bit)

✅ Always use the 32-bit ODBC Administrator for VB6 compatibility.

2️⃣ User DSN vs System DSN

⚠️ If both exist with the same name, User DSN takes priority.

3️⃣ Logical Drive vs UNC Path

  • Mapped drives (e.g., G:): ➤ Session-specific; may disappear in elevated/admin mode. ➤ Not reliable for System DSNs.

  • UNC paths (e.g., \\Server\Share\YourDB.mdb): ➤ Always accessible across sessions and users. ➤ Recommended for both System DSNs and DSN-less connections.

🛠️ Use Registry Editor to manually set DBQ to a UNC path if the GUI doesn’t allow it.

🛠️ Manually Setting DBQ to a UNC Path in the Registry

When the ODBC Administrator (odbcad32.exe) doesn't allow UNC paths in the Select Database dialog, you can manually set the database path by editing the registry.

📍 Registry Location for System DSNs (32-bit):

Code
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI\YourDSNName

🔧 Steps:

  1. Open Registry Editor (regedit.exe) as Administrator.

  2. Navigate to the key above, replacing YourDSNName with the name of your DSN.

  3. In the right-hand pane, look for a string value named DBQ.

    • If it doesn’t exist, right-click → New > String Value → name it DBQ.

  4. Double-click DBQ and enter your full UNC path:

    Code
    \\ServerName\ShareName\YourDatabase.mdb
    
  5. Close Registry Editor.

✅ Why This Works

  • The DBQ value tells the Access ODBC driver where to find the .mdb file.

  • UNC paths are session-independent and work reliably across users and privilege levels.

  • This bypasses the GUI limitation and ensures your VB6 app can connect without relying on mapped drives.


沒有留言:

張貼留言