[ACCEPTED]-Exporting ODBC System DSNs from a windows 2003 machine?-windows-server-2003
System DSN information is stored under the 4 HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI
registry key. You could export that key 3 to a .reg file and import on another machine.
UPDATE:
You 2 can also do it programmatically. Here are 1 a few examples:
http://www.codeproject.com/KB/database/DSNAdmin.aspx
I have just done this myself with a very 5 simple bat script for 32bit ODBC sources
regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI"
and 4 for the 64bit sources or if you are on a 3 32bit operating system:
regedit /e c:\backup\odbc.reg "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI"
This backs up all 2 of the DSN's however you could then specify 1 the DNS you want.
System DSN's are stored in windows registry 10 under HKLM\Software\ODBC\ODBC.INI
node
So if you export this node to 9 a *.reg file and run this reg file on a 8 target machine, it should work.
The only 7 thing, this reg file will contain some file 6 paths which maybe computer specific, eg
c:\WINNT\System32\bla-bla-bla.dll
includes 5 WINNT folder which on target machine may 4 be called like WINDOWS
. So you will need to spend 3 a bit time to make sure all paths in *.reg 2 file are correct for target machine where 1 you would finally import.
I wrote some Powershell functions for copying 12 ODBC connections from one computer to another, they 11 are posted (and kept updated) at:
http://powershell.com/cs/media/p/32510.aspx
# Usage:
# $srcConfig = Get-OdbcConfig srcComputerName
# Import-OdbcConfig trgComputerName $scrConfig
# Only returns data when setting values
function Get-OdbcConfig {
param( $srcName )
if ( Test-Connection $srcName -Count 1 -Quiet ) {
# cycle through the odbc and odbc32 keys
$keys = "SOFTWARE\ODBC\ODBC.INI", "SOFTWARE\Wow6432Node\ODBC\ODBC.INI"
foreach ( $key in $keys ){
# open remote registry
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$srcReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $srcName )
$OdbcKey = $srcReg.OpenSubKey( $key )
# red through each key
foreach ( $oDrvr in $OdbcKey.GetSubKeyNames() ){
# form the key path
$sKey = $key + "\" + $oDrvr
$oDrvrKey = $srcReg.OpenSubKey( $sKey )
# cycle through each value, capture the key path, name, value and type
foreach ( $oDrvrVal in $oDrvrKey.GetValueNames() ) {
$regObj = New-Object psobject -Property @{
Path = $sKey
Name = $oDrvrVal
Value = $oDrvrKey.GetValue( $oDrvrVal )
Type = $oDrvrKey.GetValueKind( $oDrvrVal )
}
# dump each to the console
$regObj
}
}
}
}
# can't ping
else { Write-Host "$srcName offline" }
}
function Import-OdbcConfig {
param( $trgName, $srcConfig )
if ( Test-Connection $trgName -Count 1 -Quiet ) {
# open remote registry
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$trgReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( $type, $trgName )
# sort out the key paths and cycle through each
$paths = $srcConfig | select -Unique Path
foreach ( $key in $paths ){
# check for the key and create it if it's not there
if ( ! $trgReg.OpenSubKey( $key.Path ) ) { $writeKey = $trgReg.CreateSubKey( $key.Path ) }
# open the path for writing ($true)
$trgKey = $trgReg.OpenSubKey( $key.Path, $true )
# cycle through each value, check to see if it exists, create it if it doesn't
foreach ( $oDrvr in $srcConfig | where { $_.Path -eq $key.Path } ) {
if ( ! $trgKey.GetValue( $oDrvr.Name ) ) {
$oType = $oDrvr.Type
$writeValue = $trgKey.SetValue( $oDrvr.Name, $oDrvr.Value, [Microsoft.Win32.RegistryValueKind]::$oType )
$objObj = new-object psobject -Property @{
Path = $oDrvr.Path
Name = $oDrvr.Name
Value = $trgKey.GetValue( $oDrvr.Name )
Type = $trgKey.GetValueKind( $oDrvr.Name )
}
}
$objObj
}
}
}
# can't ping
else { Write-Host "$srcName offline" }
}
Using these 10 functions together you can copy all of one 9 computers ODBC connections to another:
$srcConfig 8 = Get-OdbcConfig srcComputerName
Import-OdbcConfig 7 trgComputerName $scrConfig
It's possible 6 to include only your favorite ODBC connection 5 by filtering on the path:
Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -eq "SOFTWARE\ODBC\ODBC.INI\GoodDatabase" } )
Or filtering out 4 ODBC connections you don't like:
Import-OdbcConfig trgComputerName ( $scrKeys | where { $_.Path -ne "SOFTWARE\ODBC\ODBC.INI\DatabaseIHate" } )
Import-OdbcConfig 3 only returns data when setting values or 2 can't ping target, if there's nothing to 1 create it won't say anything.
If you can't find the registrations there, depending 3 on if they are User DSN/System DSN, they 2 can very will be in:
[HKEY_USERS\"User SID(dont' look 1 for this, it will be a long number)\Software\ODBC\ODBC.INI]
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.