# Solved: Create a ODBC connection with a script



## clmowers (Jun 20, 2005)

Hello everyone
Ok, So here is the deal. I have a My SQL database that is being used with a Access 2003 front end. Its using the MY SQL ODBC driver and a User DSN. I have to deploy this front end to about 200 people and don't want to visit each computer to do so. I need to install the drive which i have built a script to do, and i need to create a DSN. How do i create a User DSN or a system DSN with a batch file with a script. I tried to use a File DSN,Which would have made my life easy as i could just have copied that file to all the computers, But it promoted the user to log into the database when a form is open. Which is no good. Can anyone help me?


----------



## clmowers (Jun 20, 2005)

I found a code that will work, Thanks

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = "Script Repository"
strValue = "SQL Server"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\Script Repository"

objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

strKeyPath = "SOFTWARE\ODBC\ODBC.INI\Script Repository"

strValueName = "Database"
strValue = "Script Center"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Driver"
strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Server"
strValue = "atl-sql-01"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "Trusted_Connection"
strValue = "Yes"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue


----------

