Page 1 of 1 1
Topic Options
#141465 - 2005-06-10 06:32 PM User Info to SQL
Savvy95 Offline
Fresh Scripter

Registered: 2005-05-09
Posts: 11
My script is trying to retrieve user and computer info and put it into a MS SQL Db but I keep getting the error:

ERROR: invalid method/Function call: too many parameters!
Script: logon.kix
Line: 154

or i get Missing Comma! at the same location when I change the DBExecuteSQL line

;**********************************************
;BEGIN FUNCTION DB CONNECTION
;**********************************************

Function DBConnOpen($ConnDSN, optional $ConnTimeout, optional $CmdTimeout)
Dim $objConn, $adStateOpen

$dbconnopen=""

$adStateOpen=1

if vartype($ConnTimeout)
$ConnTimeout=val($ConnTimeout)
else
$ConnTimeout=15
endif

if vartype($CmdTimeout)
$CmdTimeout=val($CmdTimeout)
else
$CmdTimeout=30
endif

$ConnDSN=trim($ConnDSN)
if not $ConnDSN
exit 87
endif

$objConn = CreateObject("ADODB.Connection")
if @ERROR
exit @ERROR
endif

$objConn.ConnectionTimeout = $ConnTimeout
if @ERROR
exit @ERROR
endif

$objConn.CommandTimeout = $CmdTimeout
if @ERROR
exit @ERROR
endif

$objConn.Open($ConnDSN)
if @ERROR
exit @ERROR
endif

if not $objConn.State=$adStateOpen
$objConn=""
$DBConnOpen=""
exit @ERROR
endif
$DBConnOpen=$objConn
exit 0
EndFunction

;**********************************************
;END FUNCTION DB CONNECTION
;**********************************************


;**********************************************
;BEGIN FUCNTION DB EXECUTE
;**********************************************

function DBExecuteSQL($objConn, $sql, optional $cmdType)
dim $cmdCommand, $rsRecordset
dim $adCmdUnspecified, $adCmdText, $adCmdTable, $adCmdStoredProc, $adCmdUnknown, $adCmdFile, $adCmdTableDirect

$adCmdUnspecified = -1
$adCmdText = 1
$adCmdTable = 2
$adCmdStoredProc = 4
$adCmdUnknown = 8
$adCmdFile = 256
$adCmdTableDirect = 512

if vartype($cmdType)
$cmdType=val($cmdType)
else
$cmdType=$adCmdText
endif

if vartype($objConn)<>9 or $sql=''
exit 87
endif

$cmdCommand = CreateObject('ADODB.Command')
if @ERROR
exit @ERROR
endif

$cmdCommand.ActiveConnection = $objConn
if @ERROR
exit @ERROR
endif

$cmdCommand.CommandType = $cmdType
if @ERROR
exit @ERROR
endif

$cmdCommand.CommandText = $sql
if @ERROR
exit @ERROR
endif

$rsRecordset=$cmdCommand.Execute()
$cmdCommand=""
$rsRecordset=""
if @ERROR
exit @ERROR
endif

$DBExecuteSQL=0
exit 0

endfunction
;**********************************************
;END FUCNTION DB EXECUTE
;**********************************************

;**********************************************
;BEGIN FUNCTION DB CLOSE
;**********************************************
Function DBConnClose($objConn)
Dim $adStateOpen

$adStateOpen = 1

If vartype($objConn)=9
If $objConn.State = $adStateOpen
$objConn.Close()
if @ERROR
exit @ERROR
endif
EndIf
$objConn=""
else
exit 87
endif

$DBConnClose=0
exit 0
EndFunction
;**********************************************
;END FUNCTION DB CLOSE
;**********************************************

$objConn = DBConnOpen ("DRIVER={SQL Server};SERVER=Troy;UID=testuser;PWD=*****;DATABASE=UserTimes")

$retcode = DBCConnOpen($objConn)
$retcode = DBExecuteSQL ($objConn,"Insert into Logon (Userid, FullName, OSVer, SP, BuildNo, Workstation, Dom, DC, IP, MAC, CPU, RAM) VALUES (@USERID, @FULLNAME, @PRODUCTTYPE, @CSD, @BUILD, @WKSTA, @DOMAIN, @LSERVER, @IPINFO, @ADDRESS, @CPU, MEMORYSIZE()")
$retcode = DBConnClose ($objConn)


All Your Help is Greatly Appreciated

Top
#141466 - 2005-06-10 07:23 PM Re: User Info to SQL
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Are we supposed to count your lines to figure out what ine 154 is?
Also, please post using code tags to preserve indenting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141467 - 2005-06-10 08:07 PM Re: User Info to SQL
Savvy95 Offline
Fresh Scripter

Registered: 2005-05-09
Posts: 11
I apologize.....
Line 154 is the second to last line calling the DBExecute

Top
#141468 - 2005-06-10 08:33 PM Re: User Info to SQL
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You mean this one?
$retcode = DBCConnOpen($objConn)

If so, there is no UDF by the name DBCConnOpen(). There is however one called DBConnOpen()
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141469 - 2005-06-10 08:41 PM Re: User Info to SQL
Savvy95 Offline
Fresh Scripter

Registered: 2005-05-09
Posts: 11
thank you.

Now I'm not getting any errors. But for that matter, I'm not getting any info entered into the DB either. Can you help me with this too?

No error appears nor does the data.

Top
#141470 - 2005-06-10 09:38 PM Re: User Info to SQL
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Think you might need some single quotes around each of your VALUES
Top
#141471 - 2005-06-11 04:58 AM Re: User Info to SQL
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
First of all, for simple SQL queries, DBCommand() is a better choice. DBConnOpen and cohorts are designed for instances where you'd need to execute multiple SQL commmands and you want t keep the connection open during that time.
You will also, as already stated, have to put the values inside quotes in order to have properly formatted SQL statements.

Finally, with the advent of KiXtart 4.50 is is a bad coding habit to have macros inside strings
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 978 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.055 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org