Solved

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

Posted on 2009-04-07
9
1,770 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:Simon482
  • 6
  • 3
9 Comments
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24114937
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
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24127997
What happend ? Pl. reply if my solution is Ok.

Regards,

Bm Keshav
0
 

Author Comment

by:Simon482
ID: 24163320
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
 
LVL 6

Assisted Solution

by:BALMUKUND KESHAV
BALMUKUND KESHAV earned 500 total points
ID: 24165011
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Simon482
ID: 24166278
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
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24166427
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
 

Accepted Solution

by:
Simon482 earned 0 total points
ID: 24166806
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
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24167047
Pl.encourage the members by giving the points to the appropriate sol.provider,

Regards,

Bm Keshav
0
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24201341
What happend to this question. Not closed yet ?

Bm Keshav
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now