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
Simon482ManagerAsked:
Who is Participating?
 
Simon482ManagerAuthor Commented:
I was able to open in foxpro and have deleted the duplicate field.

I can now connect using the adodb.

Thanks for your help on this.

Simon.
0
 
BALMUKUND KESHAVCommented:
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
0
 
BALMUKUND KESHAVCommented:
What happend ? Pl. reply if my solution is Ok.

Regards,

Bm Keshav
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Simon482ManagerAuthor Commented:
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

0
 
BALMUKUND KESHAVCommented:
Creat an Access 2000 MDB and crate a module and set the following reference library and try to connect to your dbf b/c its working here for me : If your dbf has memo fields then it will create problem
then try to use visual foxpro driver inplace of dbase driver :

Microsoft Visual Basic for Applications
Microsoft Access 9.0 Object Library
Microsoft ActiveX Data Objects 2.1 Library
OLE Automation

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
0
 
Simon482ManagerAuthor Commented:
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?
0
 
BALMUKUND KESHAVCommented:
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
0
 
BALMUKUND KESHAVCommented:
Pl.encourage the members by giving the points to the appropriate sol.provider,

Regards,

Bm Keshav
0
 
BALMUKUND KESHAVCommented:
What happend to this question. Not closed yet ?

Bm Keshav
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.