?
Solved

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

Posted on 2004-08-09
11
Medium Priority
?
3,678 Views
Last Modified: 2013-12-25
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
Comment
Question by:marshmeli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 

Author Comment

by:marshmeli
ID: 11752888
I do not think that Btrieve 5.0 supports connection via ODBC.  If you know differently please let me know.
0
 
LVL 18

Accepted Solution

by:
mirtheil earned 1000 total points
ID: 11754580
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
 
LVL 2

Assisted Solution

by:tonyhowarth
tonyhowarth earned 1000 total points
ID: 11760458
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 18

Expert Comment

by:mirtheil
ID: 11761565
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
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11762614
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
 

Author Comment

by:marshmeli
ID: 11763052
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
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11763816
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
 

Author Comment

by:marshmeli
ID: 11773615
Tony that would be great...
0
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11775220
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
 
LVL 18

Expert Comment

by:mirtheil
ID: 11775392
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
 
LVL 2

Expert Comment

by:tonyhowarth
ID: 11775475
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 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