#62803 - 2002-02-05 11:01 AM
Sample script for creating an ODBC Connection
|
MasterOfDesaster
Fresh Scripter
Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
|
Hi,perhaps someone need a script like this.... This script creates or make changes to a SYSTEM-DNS SQL-Server ODBC Connection... code:
;Create a System-DNS ODBC Entry in the Registry ;M.Szekely ;;Variables $regODBC="HKLM\Software\ODBC\ODBC.ini" $regDBSName="ZMDB" $regDBSDescription="Zentrales Management" $regDBSDriver="%systemroot%\system32\SQLSRV32.dll" $regDBSUser="%Username%" $regDBSServer="SM009" ;Write the values to the registry
if not keyexist("$regODBC\$regDBSName") $RC=addkey("$regODBC\$regDBSName") $RC=writevalue("$regODBC\ODBC DATA Sources","$regDBSName","SQL Server","REG_SZ") endif $RC=writevalue("$regODBC\$regDBSName","Database",$regDBSName,"REG_SZ") $RC=writevalue("$regODBC\$regDBSName","Description",$regDBSDescription,"REG_SZ") $RC=writevalue("$regODBC\$regDBSName","Driver",$regDBSDriver,"REG_SZ") $RC=writevalue("$regODBC\$regDBSName","LastUser",$regDBSUser,"REG_SZ") $RC=writevalue("$regODBC\$regDBSName","Server",$regDBSServer,"REG_SZ") $RC=writevalue("$regODBC\$regDBSName","Trusted_Connection","Yes","REG_SZ")
[ 05 February 2002: Message edited by: MasterOfDesaster ] [ 06 February 2002: Message edited by: MasterOfDesaster ]
_________________________
Greetings,
Michael
|
|
Top
|
|
|
|
#62805 - 2002-02-05 01:59 PM
Re: Sample script for creating an ODBC Connection
|
MasterOfDesaster
Fresh Scripter
Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
|
Thanks,i'm from Munich...
_________________________
Greetings,
Michael
|
|
Top
|
|
|
|
#62806 - 2002-02-05 03:46 PM
Re: Sample script for creating an ODBC Connection
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Master,Your code looks a lot better than mine.  code:
$HKLMS = 'HKEY_LOCAL_MACHINE\SOFTWARE'; This adds in the Datatrac ODBC Connection for the Control Panel ATATRAC ;Check for the existence of the ODBC Data Sources For the Control Panel If 0 <> EXISTKEY($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources") $ = ADDKEY($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources") ENDIF If 0 = ExistKey($HKLMS+"\ODBC\ODBC.INI\DataTrac") ;IF THEY HAVE THE ODBC CONNECTION RETURN ELSE ;ADD A DATASOURCE FOR THE CONTROL PANEL $ = WRITEVALUE($HKLMS+"\ODBC\ODBC.INI\ODBC Data Sources","DataTrac","Microsoft Visual FoxPro Driver","REG_SZ") ;SET THE REGISTRY PATH STRING $ODBCPATH = $HKLMS+"\ODBC\ODBC.INI\DataTrac" ;ASSUME THE STRING DOESN'T EXIST $ = ADDKEY($ODBCPATH) ;NOW, WRITE SOME VALUES FOR THIS ODBC CONNECTION $ = WRITEVALUE($ODBCPATH,"Driver","%windir%\SYSTEM32\VFPODBC.dll","REG_SZ") $ = WRITEVALUE($ODBCPATH,"SourceDB","R:\Datatrac\Tables\datatrac.DBC","REG_SZ") $ = WRITEVALUE($ODBCPATH,"Description","","REG_SZ") $ = WRITEVALUE($ODBCPATH,"SourceType","DBC","REG_SZ") $ = WRITEVALUE($ODBCPATH,"BackgroundFetch","No","REG_SZ") $ = WRITEVALUE($ODBCPATH,"Exclusive","No","REG_SZ") $ = WRITEVALUE($ODBCPATH,"Null","Yes","REG_SZ") $ = WRITEVALUE($ODBCPATH,"Deleted","Yes","REG_SZ") $ = WRITEVALUE($ODBCPATH,"Collate","Machine","REG_SZ") $ = WRITEVALUE($ODBCPATH,"SetNoCountOn","No","REG_SZ") RETURN ENDIF
Thanks! - Kent
|
|
Top
|
|
|
|
#62807 - 2002-02-05 09:15 PM
Re: Sample script for creating an ODBC Connection
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Yes, very good one indeed!! Got my vote tooDid you get a look to see if a possibility exist to skip the need of a reboot ?
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#62809 - 2002-02-06 12:29 AM
Re: Sample script for creating an ODBC Connection
|
Alex.H
Seasoned Scripter
Registered: 2001-04-10
Posts: 406
Loc: France
|
Kent, I didn't try it for the moment, but i wanted to know about it, as MoD stated : ;Remark: The PC must be restarted to activate the changesAnyway, if it's not needed it will be really great !!! I really need some cold water on my head!! Currently finishing one blockbuster and i'll go on something with this stuff. About the current script in building state, Kent, did you ever dream of creating 50+ users in ten clicks or less (assuming your boss fill an Excel worksheet before with the new user to add (full name and groups, that's all)) ?  Hint : while playing with an AD script, I mistakely created some users on the NT4 domain using WinNT:// Active Directory provider. This little baby was only installed on my NT4 station while logged on the same domain, but not on the servers. You'll certainly see the rest, as in fact the AD methods and properties used for are working on any NT domain through WinNT:// provider [ 06 February 2002: Message edited by: Alex.H ]
_________________________
? getobject(Kixtart.org.Signature)
|
|
Top
|
|
|
|
#62812 - 2002-02-06 09:47 AM
Re: Sample script for creating an ODBC Connection
|
MasterOfDesaster
Fresh Scripter
Registered: 2002-01-23
Posts: 21
Loc: Munich, Germany
|
Hi,i was wrong, there is no reboot needed to activate the ODBC Settings. Sorry for the wrong message. I've thested the Script only on NT4, but it should work on W2K and XP also.
_________________________
Greetings,
Michael
|
|
Top
|
|
|
|
#62813 - 2002-07-31 07:23 PM
Re: Sample script for creating an ODBC Connection
|
FTPMonster
Fresh Scripter
Registered: 2002-05-30
Posts: 16
|
Can I just go on record as saying you just made my life SO easy? Thank you!
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|