Hi 59cobalt,
Thanks again for your help.
After adding the additional event logging I received this error:
Could not find file 'C:\Windows\system32\AssetInventory.mdb'. (0x80004005)
When you think about it, it makes sense. Since the "taskschd.exe" is located in the system32 folder, anything in a script with an assumed relative path is going to be looked for in the system32 folder. In my case, the assumed relative path that was failing was in the dbSource variable:
dbSource = "Data Source=AssetInventory.mdb;"
All I did to fix the issue was create a variable to hold the valid relative path information and add it to my
dbSource variable:
aScriptFilename = Split(Wscript.ScriptFullName, "\")
sScriptFilename = aScriptFileName(Ubound(aScriptFilename))
WorkingDirectory = Replace(Wscript.ScriptFullName, sScriptFilename, "")
dbSource = "Data Source=" & WorkingDirectory & "\AssetInventory.mdb;"
Below is my finalized code for accessing a database file via task scheduler:
----------code------------
Set objCon = CreateObject("ADODB.Connection")
Set objRec = CreateObject("ADODB.Recordset")
aScriptFilename = Split(Wscript.ScriptFullName, "\")
sScriptFilename = aScriptFileName(Ubound(aScriptFilename))
WorkingDirectory = Replace(Wscript.ScriptFullName, sScriptFilename, "")
dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source=" & WorkingDirectory & "\AssetInventory.mdb;"
ConnectionString = dbProvider & dbSource
objCon.Open ConnectionString
MyQuery = "SELECT * FROM Config"
objRec.Open objCon.Execute(MyQuery)
While Not objRec.EOF
Subnet = objRec("Subnet")
StartIP = objRec("StartIP")
EndIP = objRec("EndIP")
objRec.MoveNext
WEnd
objRec.Close
objCon.Close
----------code------------
Thanks again to 59cobalt for teaching me about the event viewer, logging, and the royal PITA that is debugging.
scheduled tasks.