Link to home
Start Free TrialLog in
Avatar of Simon482
Simon482Flag for United Kingdom of Great Britain and Northern Ireland

asked on

ADODC in Visual Basic 6 - error -5016 connecting to dbf

Hello experts,

I am trying to create a standard exe application in VB6 that can work with our client database, which is in .dbf format.

I have added Microsoft ActiveX Data Objects 2.8 Library and Microsoft ActiveX Data Objects Recordset 2.8 Library as references and added the ADODC component.

With the ADODC I am using a data link file named "clients.dbf.dsn" to link to the database and this contains the follwoing:

[ODBC]
DRIVER=Driver do Microsoft dBase (*.dbf)
UID=admin
UserCommitSync=Yes
Threads=3
Statistics=0
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=dBase 5.0
DriverId=533
Deleted=0
DefaultDir=S:\SimonEvans
CollatingSequence=ASCII


I have chosen the command type adCmdTable and this allows me to select the only Table contained in the database, named "clients".

I have added a text box and named the record source as the ADODC, but when I try to name the Data Field I recieve the following error:

[Microsoft][ODBC dBase Driver] Reserved error (-5016); there is no message for this error

I can find no resources about what this means, other than it is an "Unexpected error from external database driver"

I have connected to both .mdb and .dbf in this manner before and cannot work out what is going wrong.

I have tried importing the database into Access and recieve the same, or very similar, error message.

Can anyone please help?

Many thanks,

Simon
Avatar of BALMUKUND KESHAV
BALMUKUND KESHAV
Flag of India image

to connect to dbf file in vb
try this one :

Sub connecttofox()
path = "c:\bmk\"
  Set conn1 = CreateObject("ADODB.Connection")
  conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                   "Data Source=" & path & ";" & _
                   "Extended Properties=""DBASE 5.0;"";"
  Set OpenDBFConn = conn1
    foxdb = "datafile"
      Dim fldstr As String, fldstr1 As String, fldstr2 As String, fldstr3 As String
      Dim fldatrbt As FieldAttributeEnum
          fldstr = "Select * from " + foxdb
          Set rsfox = New ADODB.Recordset
          rsfox.Open fldstr, conn1, adOpenKeyset, adLockOptimistic
           MsgBox rsfox.Fields(0)
   
End Sub

Regards,

Bm Keshav
What happend ? Pl. reply if my solution is Ok.

Regards,

Bm Keshav
Avatar of Simon482

ASKER

Sorry for delay - Easter Holidays

Thanks for the code, I have tried as amended below, but received the following error "run time error -2147467259 (80004005)".

I've looked this up and see that this means "unrecognized database format". I'm wondering if it is the dbf file that is the problem (unless you can see obvious problems with the code - it's crashing at "rsfox.Open fldstr, conn1, adOpenKeyset, adLockOptimistic"). I've been using some tools from the whitetown website and they have no problem reading from the database though, although they cannot convert to Access.

otherwise, any suggestions?


Public Sub ConnectToFox()
Path = "C:\Fake Drive P\Forbes\Clients"
  Set conn1 = CreateObject("ADODB.Connection")
  conn1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Path & ";" & "Extended Properties=""DBASE 5.0;"";"
  Set OpenDBFConn = conn1
    foxdb = "clients.dbf"
      Dim fldstr As String, fldstr1 As String, fldstr2 As String, fldstr3 As String
      Dim fldatrbt As FieldAttributeEnum
          fldstr = "Select * from " + foxdb
          Set rsfox = New ADODB.Recordset
          rsfox.Open fldstr, conn1, adOpenKeyset, adLockOptimistic
           MsgBox rsfox.Fields(0)
   
End Sub

Open in new window

SOLUTION
Avatar of BALMUKUND KESHAV
BALMUKUND KESHAV
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, thanks, I have now tried that.

I am still having problems

Using the given code from a module in Access, I recieved the same run time error  -2147467259 (80004005). Unrecognised Database Format.

I changed the "Extended Properties" from ""DBASE 5.0;"";" to ""FoxPro 3.0;"";"

and recieved the following error - "Could not find installable ISAM"

So...

I added this to the registry

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\ISAM Formats\FoxPro 3.0] "Engine"="Xbase"
"ExportFilter"="Microsoft FoxPro 3.0 (*.dbf)"
"CanLink"=hex:00
"OneTablePerFile"=hex:01
"IsamType"=dword:00000000
"IndexDialog"=hex:00
"CreateDBOnExport"=hex:00
"ResultTextExport"="Export data into a Microsoft FoxPro 3.0 file."
"SupportsLongNames"=hex:00

and tried again.

just to get the same run time error -2147467259 (80004005).

A bit of investigation of the dBase file has shown that there is a duplicate field name - could this cause a problem?
How it can be possible to have a duplicate field name in any dbf/table.
Can you put your dbf file here.... /Not complete data,

Is your dbf opening in dbase/foxpro ?

I will try it at my end will be able to give you correct solution.

Bm Keshav
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pl.encourage the members by giving the points to the appropriate sol.provider,

Regards,

Bm Keshav
What happend to this question. Not closed yet ?

Bm Keshav