• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3694
  • Last Modified:

Btrieve v5.0 and VB.NET - How to Connect and Export (only selected records)?

Hey I have a Btrieve DB version 5.0 that I need to export records into a text file.  I know that I could just use the butil utiltiy and export the DB to a CSV file, but I do not need all the records, only ones that are from within is a certain range (i.e. I would like to be able to use BUTIL with a SELECT statement, but that is not an option).  This process has to be done everyday.  

I know I am using an old version of Btrive (very old, not even v6.15) but this is what I have and we cannot (or will not) upgrade.  After reading up on it, I think my option is use ODBC to connect and I am going to VB.NET to handle it.  But I do not know where to begin.  I do not know what ODBC driver to use (most I have seen are for v6.15 or Pervasive.SQL7 (or newer).  Are their drivers out there for Btrieve 5.0?  

Also can some give me some examples of how to start this task in VB.NET not VB6.  Or does anyone have any other ways that this may be performed, and if you do please also provide some examples because I probablly will not know how to do it since I am very new to Btrieve...

If people know of other tools (command line (i.e. DOS), not WIN32) that I could use for this task that would be great too.

Also I have to ask the admin of this system but I am not sure if he has the DDF files, so if they are needed in your solutions please make a note of that.

Thanks alot.
0
marshmeli
Asked:
marshmeli
  • 5
  • 3
  • 3
2 Solutions
 
marshmeliAuthor Commented:
I do not think that Btrieve 5.0 supports connection via ODBC.  If you know differently please let me know.
0
 
mirtheilCommented:
That's correct. Btrieve 5.0 was DOS, OS/2, NetWare, and Win16 based only. Which one are you using?  Also, BUTIL will NOT export CSV.  It exports as an unformatted binary record image.  Text will show correctly but other types will not.  
As far as using VB.NET, it's not going to happen with Btrieve 5.0.  You simply cannot use it.  For VB.NET, you need to use a Managed Provider, ODBC, OLEDB, or the Btrieve API (in order of personal preference).  You might be able to find an ODBC driver for 6.15, but you'll still need a WIn32 version of the engine.  
My suggestion, download the trial version of Pervasive V8, try it out.  Once you see it work, you might be able to convince the powers that be to upgrade. Not only will you get ODBC, OLEDB, a Managed Provider for .NET, support, and a stable engine in current OSes, but you'll also get backward compatibility, data file integrity improvements, and speed improvements.
0
 
tonyhowarthCommented:
There is a problem with the answer above.  Having used btrieve from version 4 we have found backward compatibilty problems particularly, using v8 with apps written for version 5 and 6.

Therefore if you have an app that uses btrieve 5 then upgrading to 8 could be more problematic than you may think.

An alternative way round this problem could be to use a DLL in the middle that offers record by record access to the data through a standard call from the .NET app to the lower level DLL (written in older C or VB) that exposes the BTRV function.

Tony
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mirtheilCommented:
Tony, You've got me beat, I've only been working with Btrieve since 1995. I have only seen a few poorly written apps that were not compatible with V8.  Usually these apps did not follow the documentation for the Btrieve API.  For example, I saw one app that had the length of the file name being passed for the Key Number on the Open call.
0
 
tonyhowarthCommented:
One of our 'poorly' written apps doesn't work!

The application appears to work fine apart from in a number of places where drop downs do not populate.  I am not suggesting that this is not a  btrv call problem, merely that we would have to change the source to find out and correct, ergo, if no access to code is available then the user is stumped.

This app worked from 6.15 right thru to 2000i sp4 including hotfixes and v8 breaks it!

Hence, my statement that v8 upgrade 'could' be more problematic than you think!
0
 
marshmeliAuthor Commented:
tony,

do you know of any of those DLLs off hand?  I would be very interested in knowing (and also are they free or not?)...
0
 
tonyhowarthCommented:
I don't think there is any that are available.  We wrote a DLL stub in the past to do what is required for one of our old apps for a customer to write a VB6 interface.

However, for your requirement it would have to be database specific.  Each table required would need a function to open, read each record and return it to the .NET app, probably in a structure.

You have to expose the function using a DllImport e.g.

//C#
[DllImport ("mydll.DLL")]
private static extern short SIMPLETABLEREADER(structure);

To be honest, having rethought it, if you can write the stub, you may as well export the data in the C program?  I can give you a little code in C to do the BTRV reads if you like.

Tony
0
 
marshmeliAuthor Commented:
Tony that would be great...
0
 
tonyhowarthCommented:
Here you go then...I have commented most and you'll have to link wbtrcall.lib into the exe an include the following header files.

It has been a while since I have used BTRV so excuse any pointer issues...I am sure someone will be quick to correct me if they are wrong.

Tony

#include <string.h>
#include <stdlib.h>
#include <dir.h>
#include "wbtrv.h"
int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,LPSTR lpszCmdParm, int nCmdShow)
{
      char sPosBlock[128];
      unsigned int uDLen=0;
      char sz[128];
      int i=0;
      char szKey[128];
      typedef struct {
            char sRef[4];
            char sName[30];
      } fdTABLE;
      fdTABLE fTABLE;

      //Create output.csv for writing
      FILE *f = fopen("output.csv", "w");
      if (f)
      {
            BTRV(1, sPosBlock, 0, &uDLen, "c:\\data\\table.dat", 0);            //Open table
            i=BTRV(12, sPosBlock, (char far *)&fTABLE, &uDLen, (char far *)&szKey, 0); //Find first Record
            while(i==0)                              //while i (status) is 0 (no error) continue
            {
                  sprintf(sz, "%s,%s\r\n", fTABLE.sRef, fTABLE.sName);      //compile output string (sprintf is slow and could be better coded)
                  i=BTRV(6, sPosBlock, (char far *)&fTABLE, &uDLen, (char far *)&szKey, 0);      // read next
            }
            BTRV(2, sPosBlock, 0, 0, 0, 0);      //close btrieve table
            fclose(f);                                                //close csv file
      }
      return 0;
}
0
 
mirtheilCommented:
Actually, the line:
 BTRV(1, sPosBlock, 0, &uDLen, "c:\\data\\table.dat", 0);          //Open table
should be:
 BTRV(0, sPosBlock, 0, &uDLen, "c:\\data\\table.dat", 0);          //Open table

Operation 1 closes the file.

0
 
tonyhowarthCommented:
Doh!, Give you that

Open=0
Close=1

Also change the close line to 1 from 2.  2 is INSERT and will probably GPF.

As I said it's been a while and we use a class to access the data, all the codes are defines, I did not want to publish the list of defines.

Tony
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now