Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table belong to database problem

Status
Not open for further replies.

thawatwong

Instructor
Aug 25, 2002
38
HK
Hi,I copy t1.dbf from database to other folder but when I try to accessed it. I've got the message that 'c:\myfox\t1.dbf is belong to c:\myfox\data1.dbc' and canot access the file.please Help.

thank for all advance
thawatwong@msu.ac.th
 
this is because the 'backlink' to the DBC is stored in the table...here is a function I modified from the book "1001 things you wanted to know about Visual Foxpro" that will show you and fix that table's backlink. Cut and paste to code below into a PRG file and run it. It will bring up two getfile dialog boxes, at the first one select your table that you can't open and at the second select the Database container that the table used to be hooked to:


strBackLink = backlink()
?strBackLink

Function BackLink
LOCAL lnParms, lnHnd, lnHdrStart, lnHdrSize, lcBackLink, lcNewLink, tcTable, tcDBCPath

tcTable = GETFILE("DBF","Locate TABLE?")
***Cancel out of this next GetFile dialog box
*if you just want to see the backlink that the dbf has currently
tcDBCPath = GETFILE("DBC","Locate DATABASE?")

DO case
CASE !EMPTY(tcTable) AND !EMPTY(tcDBCPath)
lnParms = 2
CASE !EMPTY(tcTable)
lnParms = 1
OTHERWISE
lnParms = 0
ENDCASE

*!* lnParms = PCOUNT()

*** Check that the file exists

IF ! FILE( tcTable )

ERROR "9000: Cannot locate file " + tcTable

RETURN .F.

ENDIF

*** Open the file at low level - Read Only if just reading info

lnHnd = FOPEN( tcTable, IIF( lnParms > 1, 2, 0) )

*** Check file is open

IF lnHnd > 0

*** Backlink is last 263 bytes of the header so calculate position

*** Max header size is (32 + ( 255 * 32 ) + 264) = 8456 Bytes

lcStr = FREAD( lnHnd, 8456 )

*** Field records end with 13 NULLS + "CR"

lcFieldEnd = REPLICATE( CHR(0), 13 ) + CHR(13)

lnHeaderStart = AT( lcFieldEnd, lcStr ) + 13

*** Move file pointer to header start position

FSEEK( lnHnd, lnHeaderStart )

*** Read backlink

lcBackLink = UPPER( ALLTRIM( STRTRAN( FGETS( lnHnd, 263 ), CHR(0) ) ) )

*** If we are writing a new backlink

IF lnParms > 1

*** Get the path (max 263 characters!)

tcDBCPath = LEFT(tcDBCPath,263)

*** Pad it out to the full length with NULLS

lcNewLink = PADR( ALLTRIM( LOWER( tcDBCPath ) ), 263, CHR(0) )

*** Go to start of Backlink

FSEEK( lnHnd, lnHeaderStart )

*** Write the new backlink information

FWRITE( lnHnd, lcNewLink )

*** Set the new backlink as the return value

lcBackLink = tcDbcPath

ENDIF

*** Close the file

FCLOSE(lnHnd)

ELSE

ERROR "9000: Unable to open table file"

lcBackLink = ""

ENDIF

*** Return the backlink

RETURN lcBackLink


Slighthaze = NULL
 
The quick and dirty method is after copying your table (say it's called MyTable):

USE MyTable EXCLUSIVE

You should then get a dialogue box informing you that it is part of a conatiner, which has two options: Remove the link or locate the container.

You should remove the link and the table will then become stand-alone.

Neil "I love work. I can sit and stare at it for hours..."
 
FatSlug

You should then get a dialogue box informing you that it is part of a conatiner, which has two options: Remove the link or locate the container.

You should remove the link and the table will then become stand-alone.


Just a word of caution using this method, if there were long file name (fieldname longer then 8 characters), they would get chopped down to 8 characters.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
Hi Mike!

I must admit I never gave long field names a thought ;)

However, isn't it 10 characters (normal) not 8?

Neil "I love work. I can sit and stare at it for hours..."
 
FatSlug

I must admit I never gave long field names a thought ;)

However, isn't it 10 characters (normal) not 8?


Correct it is 10 (I guess I was thinking of the 8 and 3 dos file names)
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
HI

Just a word of caution using this method, if there were long file name (fieldname longer then 8 characters), they would get chopped down to 8 characters. {/B]

I think Mike referenced fieldname and not file name. Field names could get truncated to 10 characters and not 8 charaters. (I am sure Mike will be aware .. but this must be a slip.)

The purpose I reply to this thread is that... in case, if it contains such field names and you want to migrate the table to another DBC, then.. look into

Utility to copy DBFs from one DBC to another DBC
faq184-629

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
You had me worried me there for a minute Mike ;)

I tend to always use 8.3 for filenames and 10 characters max for table names - saves a lot of typing in the long run plus the table isn't totally reliant on the container.

Neil "I love work. I can sit and stare at it for hours..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top