It goes a little something like this...
*-- Flavor SERVER, UID and PWD to taste.
*-- Change server name in SetDataBase proc as well
#DEFINE C_CONNECT_SQL "DRIVER=SQL Server;SERVER=MyServer;UID=me;PWD=*;DATABASE="
#DEFINE HKEY_LOCAL_MACHINE -2147483646 && BITSET(0,31)+2
LOCAL lnConn && connection handle for SPT
SetDataBase("LIVE", @lnConn)
* do some stuff to LIVE data
SetDataBase("STAGE", @lnConn)
* do some stuff to STAGE data
*********************************************************
PROCEDURE SetDataBase(tcDatabase, tnConnection)
* Set connection handle to current database
tnConnection=SQLSTRINGCONNECT(C_CONNECT_SQL + m.tcDatabase )
* change DSN to current database
lcRegFile = HOME()+"samples\classes\registry.prg"
SET PROCEDURE TO (m.lcRegFile)
oReg = CREATEOBJECT("Registry")
oReg.SetRegKey("DataBase",m.tcDatabase ,;
"SOFTWARE\ODBC\ODBC.INI\MyServer",;
HKEY_LOCAL_MACHINE)
SET PROCEDURE TO
RETURN m.tnConnection
ENDPROC
sorry about the wrapping... this template isn't very code friendly...