Page 2 of 2 <12
Topic Options
#22137 - 2002-08-07 11:11 PM Re: SW Inventory to DB Challenge
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
I do have the ODBC user data source Microsoft Access Driver (*.mdb) in place. A vb script successfully uses "Microsoft.Jet.OLEDB.4.0" as the provider...

Here's the test kix script. Function.udf contains the db udf collection (i.e. dbconnopen(),dbrecordopen(), etc.). The swinv.mdb exists with table and fields declared, as described above, with no records in it.

code:
call "function.udf"
$previousstate = SetOption( "WrapAtEOL", "ON" )
$objconn=dbconnopen('provider=microsoft.jet.oledb.4.0;data source=c:\program files\kixtart\kixdatabase\swinv.mdb')
? "objconn: @error @serror"
$recordset=dbrecordsetopen($objconn,"select * from inventory")
? "recordset: @error @serror"
;$retcode=dbrecordsetclose($recordset)
;$retcode=dbconnclose($objconn)
;? "retcode: @error @serror"

_________________________
We all live in a Yellow Subroutine...

Top
#22138 - 2002-08-07 11:36 PM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Try this connection string:
code:
"DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=database.mdb"

_________________________
There are two types of vessels, submarines and targets.

Top
#22139 - 2002-08-07 11:51 PM Re: SW Inventory to DB Challenge
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Changed connection string to

code:
$objconn=dbconnopen("DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=c:\program files\kixtart\kixdatabase\swinv.mdb")  

dbconnopen() succeeds, but dbrecordsetopen() fails with same error [Frown]
_________________________
We all live in a Yellow Subroutine...

Top
#22140 - 2002-08-08 03:37 PM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Try putting the pathname to the Access database in quotes since it contains spaces.
code:
$objconn=dbconnopen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ="c:\program files\kixtart\kixdatabase\swinv.mdb"')



[ 08. August 2002, 16:05: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#22141 - 2002-08-08 04:08 PM Re: SW Inventory to DB Challenge
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
No go...

Quoting the 'datasource' causes dbconnopen()to fail...
I have the firm opinion that this (is not / never was) a kix issue...
Moving on to investigate/upgrade/update/reinstall/etc the db and/or drivers...
Will post reply if/when there is a resolution...

[Update]
I'm right - I was wrong! [Big Grin]
Changes to COM Object handling in Kix 4.11/Kix 4.12 Beta seems to have fixed the problem...

Thanks again...

[ 23. September 2002, 15:50: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...

Top
#22142 - 2002-08-08 04:47 PM Re: SW Inventory to DB Challenge
bleonard Offline
Seasoned Scripter
*****

Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
Guys - this is a great thread. I've been wanting to learn this, but no programming exp. to really get into it. I too am having problems that Waltz is experiencing, so will await the solution. My question, what is the Access TABLE name being written to - Inventory?

Bill

Top
#22143 - 2002-08-09 10:12 PM Re: SW Inventory to DB Challenge
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
I'm right, I was wrong!
It's not an ODBC issue, so it (must?)/might be a kix COM syntax thingie...
[Confused] Still confused about why dbopenrecordset() fails, and will continue to pursue it.
[Wink] In the meantime, I have a workaround - just execute an sql insert into the database. It ain't purty (yet) but it works using this 'development' code...
code:
; notes: - sql reserved names include date and time.
; - changed db field names date to currentdate and time to currenttime
; - sql string values should be in 'single quotes', *not* "double quotes"
;
;*********** make a db connection *************************
$db = "c:\program files\kixtart\kixdatabase\swinv.mdb"

$cn = createobject("adodb.connection")

$cn.connectionstring = "data source=$db; provider=microsoft.jet.oledb.4.0;persist security info=false"

$cn.open()
;
;*********************** get the inventory data and write it to the db ***********
$array = GetUninstallInfo()
$vardate=@date
$vartime=@time
$varwksta=@wksta
For Each $varapp in $array
$rs = $cn.execute("insert into inventory (computername,program,currentdate,currenttime) values ('$varwksta','$varapp','$vardate','$vartime')")
;? "insert : @error @serror"

next
;
;************************ read it back from the db ****************
$rs = $cn.execute('select * from inventory')

while not $rs.eof()

? $rs.fields("currentdate") ":" $rs.fields("currenttime") "-" $rs.fields("computername") " " $rs.fields("program")

$rs.movenext

loop
;***************** clean up and go home ***********************************
$cn.close()
$cn = 0

exit 1
;******************************
Function GetUninstallInfo()
dim $Index, $Key, $RC, $Value, $RootKey
dim $progs[0]
$Index = 0

$RootKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$Key = EnumKey($RootKey, $Index)
While @Error = 0
ReDim PRESERVE $progs[$Index]
$RC = EnumValue($RootKey + $Key, 1)
If @Error = 0
$Value = ReadValue($RootKey + $Key, "DisplayName")
If $Value = ""
$Value = ReadValue($RootKey + $Key, "QuietDisplayName")
If $Value = ""
$Value = $Key
EndIf
EndIf
Else
$Value = $Key
EndIf
$progs[$Index] = $Value
$Index = $Index + 1
$Key = EnumKey($RootKey, $Index)
Loop
$GetUninstallInfo = $progs
EndFunction


bleonard...
Refer to clpowell's original post that started this thread re database structure...
In my incarnation
The database name is swinv.mdb
The table name is inventory
The field names are computername,program,currentdate,currenttime
and my database weapon is MS Access 97

Cheers...
_________________________
We all live in a Yellow Subroutine...

Top
#22144 - 2002-10-22 11:30 AM Re: SW Inventory to DB Challenge
Paco Offline
Lurker

Registered: 2002-10-22
Posts: 1
Loc: Brussels
Hi,

The 4.11 still creates the same error (-2147352567 System Error=COM exception error "Execute" (ADODB.Command - The connection cannot be used to perform this operation. It is either closed or invalid in this context.) [-2147352567/80020009]
) on a connection to an SQL server DB. I checked with 4.02 and it works.
I saw that you used 4.12 Beta: where can I find this version?

Thanks
_________________________
Paco Marcelis

Top
#22145 - 2002-10-22 11:34 AM Re: SW Inventory to DB Challenge
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
check on beta forum for download links on beta's.
_________________________
!

download KiXnet

Top
#22146 - 2002-10-22 03:21 PM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Paco: KiXtart 4.10 and 4.11 are a NO-GO with regards to a lot of COM functions.
_________________________
There are two types of vessels, submarines and targets.

Top
#22147 - 2005-03-02 12:26 PM Re: SW Inventory to DB Challenge
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
_________________________
How can you know good, unless you experience bad.

Top
#22148 - 2005-03-02 05:01 PM Re: SW Inventory to DB Challenge
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
KRAY,
Your practice of dredging up old posts without adding anything of value must stop.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#22149 - 2005-03-03 03:26 AM Re: SW Inventory to DB Challenge
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
I am sorry.
I had written something but it didn`t show....

I used the script to log to database.
This worked wonderfully...
I did notice that this writes entries everytime a workstation runs the script.
Is there any way to ensure that if entries exist for a workstation, that they are only updated, not new ones created again?
_________________________
How can you know good, unless you experience bad.

Top
#22150 - 2005-03-03 04:28 AM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You will need to change the code in order to create an UPSERT that either performs an INSERT or UPDATE depending on the criteria you set.
_________________________
There are two types of vessels, submarines and targets.

Top
#22151 - 2005-03-03 04:30 AM Re: SW Inventory to DB Challenge
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
Any ideas on how to do that???
_________________________
How can you know good, unless you experience bad.

Top
#22152 - 2005-03-04 01:22 AM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Yes. However, as I stated, this functionality needs to be adjusted to yoru specific requirements. The basic approach woudl be
Code:

IF (SELECT COUNT(*) FROM table WHERE attribute='aaa') THEN
UPDATE attribute(s)
ELSE
INSERT new row


Please be aware that the example above represents pseudo-code.
_________________________
There are two types of vessels, submarines and targets.

Top
#22153 - 2005-03-04 02:22 PM Re: SW Inventory to DB Challenge
ClientMaster Offline
Fresh Scripter

Registered: 2005-01-19
Posts: 46
Loc: Tokyo, Japan
I am still having trouble.
The records are being created...

I was wondering if anyone knew how to change the SQL:
Delete from Tablename where Fieldname = 'ComputerName'

Insert TableName (Field1, Field2, Field3) values (1, 'computername', 'software')

into KIX language...
I also noticed that this lists all the software in the same field... Is there a way to have it create 1 record for each PC, and then add fields for varying amount of software installed?
_________________________
How can you know good, unless you experience bad.

Top
#22154 - 2005-03-05 12:54 AM Re: SW Inventory to DB Challenge
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You cannot convert SQL to KiXtart.

You might want to learn a little bit about databases and normalizations, e.g. 3rd Normal form.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 2 of 2 <12


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

Who's Online
1 registered (Allen) and 905 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.104 seconds in which 0.059 seconds were spent on a total of 13 queries. Zlib compression enabled.

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