Sign in to follow this  
Followers 0
TuMiM

ODBC Search

1 post in this topic

Is there a way to search throuch the OBDC.INI keys in the registry one by one by Database name (The database name does not always match the connection name) in order to change the server name it points to?

Right now i have a script to add an ODBC connection but i want to make sure somehow that there is not another connection with a different connection name pointing to the wrong server. I am sure there s a way but I just haven't figured it out.

$dsn = "WinMLS"
$db = "WinMLS"
$server = "MiaQSQL01"
ODBCWrite()

If RegRead("HKCU\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "server") = "miasql2" Then
    RegDelete("HKEY_Current_User\SOFTWARE\ODBC\ODBC.INI\" & $Dsn)
    RegDelete("HKEY_Current_User\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", $Dsn)
    ENDIF

Func ODBCWrite()
            If RegRead("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "Database") = "" Then
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn)
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "Database", "REG_SZ", $db)
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "Driver", "REG_SZ", _
                @SystemDir & "\SQLSRV32.dll")
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "LastUser", "REG_SZ", _
                "MlSuser")
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "Server", "REG_SZ", $server)
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\" & $dsn, "Trusted_Connection", _
                "REG_SZ", "Yes")
                RegWrite("HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", $dsn, "REG_SZ", _
                "SQL Server")
            EndIf
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0