Hi all,

I'd like to test the UDF for creating an SQL ODBC that Kent Dyer created (post number 83212)

I'm trying to understand which aspects of the function I need to customize in order for them to work in my environment.

In his function it says
Quote:

EXAMPLE ODBCSQL('ODBC DATABASE NAME','SERVER','DATABASE')



Do I need to create associated entries for these? Example: "$NAME = dbsvr1"

I seem to remember reading someone say that UDFs should RARELY be edited, so please correct me if I'm wrong.
As you can tell, the logic is a little confusing to me at this time.

Thanks, Matthew
Code:
 

;FUNCTION ODBCSQL()
;
;ACTION Creates an ODBC Connection on the Client Desktop to a SQL Server Database
;
;AUTHOR Kent Dyer leptonator@hotmail.com
;
;CONTRIBUTORS
;Dixan Martinez
;Ref. - Create a DSN to access a SQL Server database with ODBC
;http://cwashington.netreach.net/depo/view.asp?Index=388&ScriptType=vbscript
;
;VERSION 1.3 - REMOVED UNEEDED code, Added option to create User DSN
; 1.2 Added in DIM Statement
; 1.1
; Renamed to be ODBCSQL
;
;DATE CREATED 14-APRIL-2003
;
;DATE REVISED 14-AUGUST-2004
;
;KIXTART Minimum required Kixtart version 4.02
;
;SYNTAX ODBCSQL($NAME,$SERVER,$DB,optional $user)
;
;PARAMETERS $NAME
; Name to be listed in the ODBC Connections in the Control Panel
;
; $SERVER
; Server you need to connect to
;
; $DB
; Database on $Server
;
; $USER
; Specified USER DSN
;
;RETURNS Nothing
;
;REMARKS User would need to be a Power User or better to run this Function.
; When creating a User DSN, should be able to run as a user of the machine.
;
;DEPENDENCIES SQL Server, KiXtart 4.02 +
;
;EXAMPLE ODBCSQL('ODBC DATABASE NAME','SERVER','DATABASE')
;
;IF NOT KEYEXIST('HKCU\SOFTWARE\ODBC\ODBC.INI\YOUR ODBC')
; ODBCSQL('ODBC DATABASE NAME','SERVER','DATABASE',1)
;ENDIF
;
;KIXTART BBS http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=83212
FUNCTION ODBCSQL($NAME,$SERVER,$DB,optional $user)
DIM $reg,$Title,$Driver,$RegEd,$RegEdPath,$RC
IF NOT $user
$reg='HKLM' ; System DSN
ELSE
$reg='HKCU' ; User DSN
ENDIF
$Title='SQL Server'
$Driver=READVALUE('HKLM\SOFTWARE\ODBC\ODBCINST.INI\'+$Title,'Driver')

$RegEd=$reg+'\SOFTWARE\ODBC\ODBC.INI'
$RegEdPath=$RegEd+'\'+$Name

IF NOT KEYEXIST($RegEdPath)
$RC=ADDKEY($RegEdPath)
$RC=WRITEVALUE($RegEdPath,'Database',$DB,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Driver',$Driver,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'LastUser',@USERID,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Server',$Server,'REG_SZ')
$RC=WRITEVALUE($RegEdPath,'Trusted_Connection','Yes','REG_SZ')
$RC=WRITEVALUE($RegEd+'\ODBC Data Sources',$Name,$Title,'REG_SZ')
ENDIF
ENDFUNCTION