remove odbc system dsn using batch file and odbcconf


  • I create user system dsn entries by using a batch file and odbcconf call.  I've found references here on how to do that, yet cannot seem to find any results on how to remove them using that same call.  The library information ( states add and modify a system dsn for configdsn and configsysdsn and references equivalent to SQLConfgDataSource function. ( but the config data source function has a a removal and this doesn't seem too. 

    Apologies for being obtuse, but I can't seem to locate it.  Any links to how this is done from a batch file are much appreciated.


    Monday, October 05, 2009 7:11 PM

All replies

  • If you do find a way through odbcconf, please post it or email me, so we can update the documentation.  The only way I know to do it is to delete the registry key for the DSN:

    System DSN:
    -- native
    -- WoW

    User DSN:
    -- native
    -- WoW

    Hope that helps, and if you do find a way through odbcconf -- please do email me and post the method on the forum!


    This post is provided 'as is' and confers no express or implied warranties or rights.
    Monday, October 05, 2009 8:03 PM
  • John C is basically correct, you can remove a System ODBC data source via the registry, but there is apparently no way via odbcconf.exe.  That is of course really stupid and poor programming!

    John, however, forgot another important registry entry.  That key deletion he mentioned will disable the odbc connection, but not remove it entirely.  If you just do that and then open the "ODBC Data Source Administrator", you will find the connection is still listed, but you can't remove it or modify it.  It becomes completely screwed up! There is a value to delete as well which dictates if the connection is listed.  Consider it the "header" to the data source.

    Also, in Windows 2003 and 2008 at least, the registry key John C listed is not quite the location to modify either.  This is where to find them in those OSs:




    The "header" I reffered to is a string value in inside a key (not the whole key!)




    The string value is the data source name.  This entry must be removed to remove the data source listing entirely.

    Here are some batch snipets for creating and then removing an odbc data source.  I'm leaving out some premiliary chunks, but you can figure it out from here. If you can't, you probably shouldn't be messing with this stuff in the first place!

    In these scripts, I create and remove a 32-bit data source in either a 32-bit or 64-bit version of windows.  The windows folder variable gets set to either "C:\Windows\System32" or "C:\Windows\SysWOW64" depending on the os.  In case you didn't know, on a 64-bit machine there is are also 2 differrent versions of the "ODBC Data Source Administrator" gui tool and the data source lists differ (32-bit vs 64-bit lists).  The 32-bit version on a 64 bit OS is found at "C:\Windows\SysWOW64\odbcad32.exe".  The one in the start menu will load the 64-bit version so you will never find your 32-bit connections there.

    Note - for simplicity I use the database name as the user name and and the data source name as well (in case there was any confusion). 

    Create the connection like so:

    echo Creating 32-Bit System ODBC Connection "%DatabaseName%"...
    "!WindowsFolder!\ODBCCONF.EXE" CONFIGSYSDSN "!ODBCDriver!" "DSN=%DatabaseName%;Server=localhost;Port=3306;Database=%DatabaseName%;UID=%DatabaseName%;PWD=%DatabasePassword%" 


    And then remove it like this:

    echo Removing 32-Bit System ODBC Connection "%DatabaseName%"...
    if "%WindowsBits%"=="32" ( 
     If Exist "!TempRegFile!" Del "!TempRegFile!"
     echo Windows Registry Editor Version 5.00>>"!TempRegFile!" 
     echo [-HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\%DatabaseName%]>>"!TempRegFile!"
     echo [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]>>"!TempRegFile!"
     echo "%DatabaseName%"=->>"!TempRegFile!"
     regedit /s "!TempRegFile!"
    ) else (
     If Exist "!TempRegFile!" Del "!TempRegFile!"
     echo Windows Registry Editor Version 5.00>>"!TempRegFile!" 
     echo [-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\%DatabaseName%]>>"!TempRegFile!"
     echo [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources]>>"!TempRegFile!"
     echo "%DatabaseName%"=->>"!TempRegFile!"
     regedit /s "!TempRegFile!"
    If Exist "!TempRegFile!" Del "!TempRegFile!"


    • Proposed as answer by Buvin Tech Thursday, February 10, 2011 9:08 PM
    Thursday, February 10, 2011 8:59 PM
  • Another way is to use the PowerShell cmdlet: Remove-OdbcDsn, if you're on Win8 / Server 2012 (or later).

    Pak-Ming Cheung - MSFT

    Wednesday, March 26, 2014 4:12 PM