Convert DAO from VB6 to VB8?

D

Dick Monahan

I have a little VB6 program that dumps the schema of an Access 97 database.
The following lines of code are relevant.

Private m_wsDb As DAO.Workspace
Private m_db As DAO.Database

Set m_wsDb = DBEngine.CreateWorkspace("MainWS", "admin", vbNullString)
Set m_db = m_wsDb.OpenDatabase(m_zDbFilePath, False, False, "")

Dim tdf As TableDef
Dim fld As DAO.Field

For Each tdf In m_db.TableDefs
On Error GoTo Form_Activate_Err_Tabledef
Debug.Print "Table "; tdf.Name; " ("; tdf.RecordCount; "records )."
On Error GoTo Form_Activate_Err_Field
For Each fld In tdf.Fields
Debug.Print " Field "; fld.Name; " ("; GetFieldType(fld.Type); ": ";
fld.Size; ")."
Next fld
Next tdf

I converted the program to VB8 (.NET if you prefer). As far as I can see,
the only relevant lines that it changed are these two.

m_wsDb = DAODBEngine_definst.CreateWorkspace("MainWS", "admin",
vbNullString)

Dim tdf As DAO.TableDef

When I try to read the Access 97 database with the VB8 program, it opens the
workspace and the database, but when I try to fetch a field, I get:

A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in
ExportSchema.exe

And Err = 3219 (Invalid operation.).

I also have the same database in Access 2000 and 2003 formats. When I try to
read either of them with the VB8 program, I get:

A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in
ExportSchema.exe

And Err = 3343 (Unrecognized database format '<path>'.

What have I missed in converting VB6 -> VB8?

Dick.
 
C

Cor Ligthert [MVP]

Dick,

Noboby is using the name VB8 as nobody is using NT5 or NT51 what is your
purpose with this message, to get help or to start a discussion? Try to make
a clear message as readable for those you ask help from as possible.

As well can you when you have troubles to look at true dotNet code, although
this is converted, is seldom somebody in these newsgroups intrested to take
old converted code.

Here a sample of that

http://www.vb-tips.com/dbpages.aspx?ID=26f91edd-044c-4e71-8c6c-e9d7983c1e05

I hope this helps,

Cor
 
J

Jim Wooley

I suspect in this case, you are having a problem with the DAO reference.
If I recall correctly, DAO was dropped from MDAC around version 2.6. You
might need to find an older copy of MDAC and use that to install DAO if you
want to continue using that for your data access API.

If you are migrating an application to .Net, you should consider migrating
your data access code from DAO to Ado.Net. There are no automatic upgrade
paths that I know of from DAO to ADO.Net.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top