Solved

How to fix orphan DBF

Posted on 2014-02-06
9
647 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
  • 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
Technology Partners: 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!

 

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
HOW TO GET AN EXE FILE MADE IN VISUAL FOXPRO 7 51
SQL Server 2005 - Linked FoxPro 8 633
Remove duplicates values. 14 68
Write Caching in the Cloud for VFP9 16 128
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…
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.

726 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