Command line to change path to .mdb file for MS Access ODBC System DSN?

谁说我不能喝 提交于 2019-12-06 12:05:37

问题


What odbcconf.exe command line can I use to change the path to the MS Access .mdb file for an already existing System DSN?


回答1:


To answer the question as asked, here is a solution using odbcconf.exe instead of going straight to the registry:

odbcconf.exe configsysdsn ^
  "Microsoft Access Driver (*.mdb, *.accdb)" ^
  "DSN=OurConnectionName;DBQ=X:\Path\to\OurMsAccessDB.mdb"

Two items of note which had me tripped up for a while:

  • make sure you use 64bit odbcconf.exe when on a 64bit system, see https://stackoverflow.com/questions/6721702/windows-7-64-bit-odbc-drivers-for-ms-access-missing.
  • use DBQ= and not Database= for the mdb path. When using the latter everything appears to work, however the connection link is named but not actually defined in the ODBC Administrator.



回答2:


You would have to do it by changing the registry. Something along the lines of this example taken from the net that I have used before

rem -----Author: Jim Michaels
rem -----copy the drivers where all good little ODBC drivers go
if errorlevel 1 goto bye
copy myodbcd.dll C:\WINDOWS\SYSTEM
if errorlevel 1 goto bye
rem ----create a .REG file to make registry entries
echo REGEDIT4>myodbc.reg
echo.>>myodbc.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\MySQL]>>myodbc.reg
echo "APILevel"="2">>myodbc.reg
echo "ConnectFunctions"="YYN">>myodbc.reg
echo "Driver"="C:\\WINDOWS\\SYSTEM\\myodbc.dll">>myodbc.reg
echo "DriverODBCVer"="02.50">>myodbc.reg
echo "FileExtns"="*.txt">>myodbc.reg
echo "FileUsage"="0">>myodbc.reg
echo "Setup"="C:\\WINDOWS\\SYSTEM\\myodbc.dll">>myodbc.reg
echo "SQLLevel"="1">>myodbc.reg
echo.>>myodbc.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers]>>myodbc.reg
echo "MySQL"="Installed">>myodbc.reg
echo.>>myodbc.reg
rem -----install the registry entries by executing the .REG file
start /wait myodbc.reg
rem ----clean up after we are done installing
del myodbc.reg
:bye

If you look at your existing DSN config in the registry then you will get an idea of how to modify the code to suit your situation



来源:https://stackoverflow.com/questions/3417142/command-line-to-change-path-to-mdb-file-for-ms-access-odbc-system-dsn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!