Page 1 of 1 1
Topic Options
#115377 - 2004-03-02 11:05 PM DBCommand() contention?
Gr33nScr3w Offline
Fresh Scripter

Registered: 2003-10-16
Posts: 10
I'm using DBCommand to collect data from workstations that execute a script. Each execution writes to 2 separate tables, and I'm finding that they don't always get written to. I noticed in looking at the UDF it has a section for paramaters and wondering if the $adLockReadOnly = 1 might be part of my problem? Is it OK to modify these parameters?

Code:
  
; default database parameters
$adStateOpen=1
$ConnTimeout=15
$CmdTimeout=30
$adCmdText = 1
$adOpenStatic = 3
$adLockReadOnly = 1



Or is it possible I'm using it incorrectly? Here is the section of the code that writes the data:
Code:
 

$dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\servername\servershare\dbdirectory\migrate.mdb'
$CHKMigUser="SELECT COUNT (MigUser) FROM MigUsers WHERE MigUser='$userid'" ; add? -> AND MigDate='$MigDate'"
$CHKMigComputer="SELECT COUNT (MigComputer) FROM MigComputers WHERE MigComputer='$wksta' AND MigDate='$MigDate'"
$MigAMAmountAM="SELECT Count (MigComputer) FROM MigComputers WHERE (MigDate='$MigDate') AND (MigTime='AM')"
$MigAMAmountPM="SELECT Count (MigComputer) FROM MigComputers WHERE (MigDate='$MigDate') AND (MigTime='PM')"
$MigUsers="INSERT INTO MigUsers (MigUser,LDomain,MigComputer,MigDate,MigTime)VALUES('$userid','$LDomain','$wksta','$MigDate','$MigTime')"
$MigComputers="INSERT INTO MigComputers (MigComputer,CDomain,User,MigDate,MigTime,StepReached,OS,NTBased,LocalAdmin,GrpAddReturn) VALUES('$wksta','$CDomain','$userid','$MigDate','$MigTime','$StepReached','$OS','$InWin','$LAdmin','$grpadd')"

If $LDomain<>"ActiveDirectory" ;check that user isn't already logging in to ActiveDirectory
$recordset = DBCommand($dsn,$Migusers) ; populates user data
$MessageText1="User Acct Migration: Scheduled for $MigDate."
Else $MessageText1="User Acct Migration: User currently logged in to ActiveDirectory, no migration needed!"
Endif

$recordset = DBCommand($dsn,$CHKMigComputer) ;check uniqueness of computer/migdate
$RecordUnique=+$recordset[$row,$column]
If $RecordUnique<1
$recordset = DBCommand($dsn,$MigComputers) ; populates computer data
Else $MessageText="Computer Migration: ALREADY scheduled for migration on $MigDate!"
Endif

IF $MigTime=AM ; this section runs only for AM migrations to do max 99 users
$recordset = DBCommand($dsn,$MigAMAmountAM) ; retrieve number of AM computer migrations
$AMAmount=$recordset[$row,$column] ; $AMAmount equals the number of current AM migrations
IF $AMAmount >79 ;if more than 99 migrations, write flag file to prevent any future additions
$nul=redirectoutput("\\servername\servershare\dbdirectory\"+$migdate+""+$migtime+".flg",0)
? $AMAmount
$nul=RedirectOutput("")
ENDIF
Endif

IF $MigTime=PM ; this section runs only for PM migrations to do max 1500 users
$recordset = DBCommand($dsn,$MigAMAmountPM) ; retrieve number of PM computer migrations
$AMAmount=$recordset[$row,$column] ; $AMAmount equals number of current PM migrations
IF $PMAmount >=599 ;if more than 600 migrations write flage file to prevent any future additions
$nul=redirectoutput("\\servername\servershare\dbdirectory\"+$migdate+""+$migtime+".flg",0)
? $AMAmount
$nul=RedirectOutput("")
ENDIF
Endif




Top
#115378 - 2004-03-03 03:48 PM Re: DBCommand() contention?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Code:

$MigUsers="INSERT INTO MigUsers (MigUser,LDomain,MigComputer,MigDate,MigTime)VALUES('$userid','$LDomain','$wksta','$MigDate','$MigTime')


has a missing space before VALUES.

Also, you never check the error codes that are returned by DBCommand(). Put appropriate error checking in place as it woudl tell you if something goes wrong. That's why functions (and UDFs) return error codes in the first place!

Finally, I highly recommend to use
Code:

$rc=setoption('explicit','on')
$rc=setoption('novarsinstrings','on')


as the first lines of your script as this will eliminate the most common scripting errors.

Thus, amend the code with these headers, put error checking in place, test again. If you still have problems, post the revised code and I'll take a closer look at it.
_________________________
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
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.127 seconds in which 0.103 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