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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming DBC

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

I want to use a form which was created in vfas app. And, I want to copy that form in a new app village but it is giving an error "Error instantiating cursor object. Cannot find d:\vpckg\vfas.dbc."

Is it possible to rename dbc(vfas) to dbc(village).

Thanks

Saif
 
It looks like you have some tables in the form's data environment, and those tables belone to VFAS.DBC.

If so, the simplest solution would be to remove the tables from the data environment, and then add back the corresponding tables from Village.DBC.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike might be right, but in any case just renaming a dbc is most probably not solving your problem.

If you want to copy a whole project working with the same data and you rename the project of the copy, that works fine, but renaming a DBC doesn't work this wey. Each DBF has a backlink to it's DBC in it's header and there is no command I know of to rename a dbc, so it also changes all dbf headers to point to the new dbc name.

The easiest thing is to keep your dbc name as it was. the backlinks are relative (unless you have the dbc on a totally different drive than dbfs, which you hopefull not do) and so the dbfs will refer to the dbc copy and not to the original dbc and everything should work fine, if you just have a copy of the original project and database files.

Bye, Olaf.
 
there is no command I know of to rename a dbc, so it also changes all dbf headers to point to the new dbc name.

I can't think of a command that does that either. But what about this: add the database to a project; right-click on the database; select Rename ...? I don't know whether that would work or not. I'll try it and report back.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
No, it doesn't work.

First, it's fairly difficult to rename a database from within the project. If the database node is expanded, then the database will be open behind the scenes. And as long as it's open, you can't rename it. So you have to collapse the node, then issue CLOSE DATABASE, then do the renaming.

But that doesn't fix the backlinks. When you try to open any of the tables, you get a backlink error.

It seems odd that the Fox team gave us the apparent ability to rename the database within the project, but doing doesn't actually work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There is one thing you can do:

Use GENDBC.PRG from the HOME()+"TOOLS" folder and create a script, which creates a new (but empty) database with its tables.
In the generated script you can of course rename the DBC and since all the table are regenerated, they get the right backlink.

There are a few older threads with that topic here:
thread184-1410361
thread184-368087

It's not an easy thing.

Another thing you can do is FREE TABLE to free table from an old DBC and ADD TABLE to add it to a new DBC, but: this only works, if you don't have default values, long fields names and anything else only DBC tables support, because FREE TABLE frees a table in all aspects, it becomes a free table.

I'd prefer recreating the DBC via GENDBC. To copy over data you can use APPEND, because the table structures will match exactly there is no data loss to expect.

Bye, Olaf.
 
Haven't checked out your links, but this sort of thing is one reason I put quite a bit of thought into naming a DBC from the start and try very hard not to use features that might cause havoc if the backlink gets destroyed.

I'm also wondering if using SDT would make this easier since it holds all the metadata needed to build your DBC/DBFs from scratch, it should be pretty easy to hack sdtmeta.dbf. I don't have a copy on this machine to test, though. (And I'm a little out of practice.)

 
There are a few older threads with that topic here:
thread184-1410361: Renaming tables within a DBC
thread184-368087: Rename a Database programmatically

Amazing. The first of those threads was started by myself, but I have no memory of writing any of the posts, and I don't know why I needed to ask the question in the first place. True, it was eight years ago, but even so. (By the way, it's not directly related to Saif's original problem, for which removing the tables from the data environment and adding them back would seem to be the best solution.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>removing the tables from the data environment and adding them back would seem to be the best solution.
As far as I understood saif renamed the dbc copy and therefore got the error
VFP said:
"Error instantiating cursor object. Cannot find d:\vpckg\vfas.dbc."

And that's because the copied dbfs still refer to a vfas dbc and not a village dbc.

To be able to rename the dbc to village you will need to go to the pain of any of the solutions given in the other threads or use GENDBC and rename the database in the script before generating the new dbc.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top