Solved

How to fix orphan DBF

Posted on 2014-02-06
9
650 Views
Last Modified: 2014-02-06
I want to remove the backlink to the DBC, in order to open the DBF, although it is orphan. The DBF is unknown, and it should be opened programatically, without user intervention.

There is no need to recreate the DBC, only to open the DBF. I have tried the code below, but not successful. Anybody that can give a solultion?

LPARAMETERS cFile
close databases all
cFiel = ForceExt(cFil, 'DBF')
nHnd = FOPEN(cFil, 2)

cStr = Fread(nHnd, 400)
nPos1 = 0
nPos2 = At('.dbc', cStr) + 2
jj = nPos2
for jj=nPos2 to 1 step -1
      cTkn = Substr(cStr, jj, 1)
      if cTkn = Chr(13)
            nPos1 = jj
      endif
next
for jj=nPos1 to nPos2
      =Fseek(nHnd, jj)
      =Fwrite(nHnd, Chr(0))
next
=Fseek(nHnd, 28)
=Fwrite(nHnd, Chr(0))
=Fclose(nHnd)
0
Comment
Question by:krhag28
[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
9 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 39838482
The code needs a small fix:
LPARAMETERS cFile

close databases all
cFil = ForceExt(cFile, 'DBF')
nHnd = FOPEN(cFil, 2)

cStr = Fread(nHnd, 400)
nPos1 = 0
nPos2 = At('.dbc', cStr) + 2
jj = nPos2
for jj=nPos2 to 1 step -1
      cTkn = Substr(cStr, jj, 1)
      if cTkn = Chr(13)
            nPos1 = jj
      endif
next
for jj=nPos1 to nPos2
      =Fseek(nHnd, jj)
      =Fwrite(nHnd, Chr(0))
next

*-- This code removes MEMO file and CDX indication
*=Fseek(nHnd, 28)
*=Fwrite(nHnd, Chr(0))

=Fclose(nHnd) 

Open in new window


BUT be careful!  If user selects non DBF file having DBF extension it will overwrite it...  Above code also does not work for tables having too many columns...

So it would need some additional tuning. I can provide better code later.
0
 

Expert Comment

by:krhag
ID: 39838514
I have tried it on a DBF which has CDX as well as DBC backlinks, and unfortunately the DBF seems to get corrupt, Foxpro reports Not a table...

I attach the table after manipulation with your code (including the last lines).

(txt extension because of upload restrictions)
Accounts.txt
0
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39838701
Yes, this is the case I've mentioned above... Fortunately, the fix is easy. Open the table in Hex editor and write 30h to the first byte. The Hex editor is a part of VFP tools:

DO HOME()+'\tools\hexedit\hexedit.app'


=====================  SOLUTION to the question ==============================
To remove the database reference from DBF table is also very easy because VFP offers command to do this work:

FREE TABLE d:\path\table.DBF

I should look at the help earlier...

Remember the free table cannot support database stuff like long column names, triggers, field validations etc. You should copy the DBF file (+FPT and CDX) to some temp folder as the first step.
0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

Expert Comment

by:krhag
ID: 39838907
Thanks for your comments. However, what I need is code to remove references completely without user intervention - using hex editor is not an option in this case.
0
 

Expert Comment

by:krhag
ID: 39838909
I will test the FREE TABLE command...
0
 

Expert Comment

by:krhag
ID: 39838927
Free table seems to work fine :)  so it was more simple than expected.
0
 

Author Closing Comment

by:krhag28
ID: 39838942
Simple solution, but nevertheless useful!
0
 
LVL 42

Expert Comment

by:pcelba
ID: 39838951
FREE TABLE should work but I'll post the updated code as I promised. The biggest problem of the code is it does not read the table structure but just the first 400 bytes so if you select any table having approx. 13 or more columns it must corrupt the table header...

The Hex editor was not the solution for your users but for you only.
0
 

Expert Comment

by:krhag
ID: 39839073
Thanx.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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