WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Ole Exception ParentCatalog ADOX

 Keywords: Ole Exception ParentCatalog ADOX 1261 

Question:

I am attempting to use ParentCatalog in my ADOX script, but I keep getting an OLE Exception.

The wwwbatch.ini file contains the following error information.

[OLE Exception]
ADOX.Table=Object is no longer valid.
Here is my script:
----------------------------------------

file = "C:\TEMP\NEW.MDB" ; change to suit your situation

If FileExist(file) == @TRUE
  FileDelete(file)
Endif

Conn="Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=%file%;Jet OLEDB:Engine Type=4"

BoxOpen("Creating New ACCESS Database...",Conn)

cat = ObjectOpen("ADOX.Catalog")

cat.Create(Conn)

tbl = ObjectOpen("ADOX.Table")
tbl.Name = "MyTable"

; this next line will fail
tblA = tbl.ParentCatalog ; <----- OLE Exception
;[OLE Exception]
;ADOX.Table=Object is no longer valid.

tblA = cat

ObjectClose(tbl)
ObjectClose(cat)

BoxShut()
exit

----------------------------------------

Answer:

I compared your code to sample code I found, and it seems that the OLE exception on the "tblA = tbl.ParentCatalog" assignment is occuring simply because tbl.ParentCatalog has not been assigned a value, and therefore has never pointed to a valid catalog object.

I re-wrote the code to create a catalog and table as follows, which seems to work. I found the Delay to be necessary, but the time could be tweaked.

----------------------------------------

;-----------------------
file = "C:\TEMP\NEW.MDB"
;-----------------------

If FileExist(file) Then FileDelete(file)

cat = ObjectOpen("ADOX.Catalog") 
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%file%;Jet OLEDB:Engine Type=4")

tbl = ObjectOpen("ADOX.Table")
tbl.Name = "MyTable"
tbl.ParentCatalog = cat ;<----------Added
x = tbl.ParentCatalog

tbls = cat.Tables
tbls.Append(tbl)
Delay(1)

ObjectClose(tbls)
ObjectClose(tbl)
ObjectClose(cat)

----------------------------------------

Article ID:   W15600
File Created: 2003:05:13:11:29:10
Last Updated: 2003:05:13:11:29:10