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

How to avoid "alias is not found" in error.

Status
Not open for further replies.

koklimabc

Programmer
Jun 17, 2013
49
MY
Dear all,

I've simple question need to ask you all. Why the error is keep coming even i've select alias where it is under different work area.

use in select("tmpcur_")
use dbf("tmpcur") in 0 again alias tmpcur_ exclu
use in tmpcur

if file(vl_tmpfile)
use in select("vc_tmp")
use (vl_tmpfile) in 0 again alias vc_tmp exclu
use in (vl_tmpfile)
endif

select tmpcur_ =>The error "The alias is not found" at here.

Thanks anyone could help.
 
I answered this question in another forum. In my mind, it's not polite to ask the same question in different forums within just a few minutes. If you don't get a good answer in one forum within a day or two, then you have a valid reason to ask in another forum.
 
I'm not sure I agree with Tbleken about posting in different forums. Different people use different forums, and the people who see your post in Tek Tips aren't necessarily going to see it anywhere else. But I won't press the point.

I have to say that your code is a bit of a mess. You seem to be opening and closing tables without any obvious logic. And you are using two aliases - tmpcur and tmpcur_ - which are identical except for the trailing underscore. Have you any special reason for doing that? What are you trying to achieve?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Different people means different answers. And different answers often means much more confusion. At least that's my impression. I have seen numerous cases where people give answers not in order to really help, but to "impress" people by showing that a simple problem can be solved in many different ways. Helpful? No, not the least.
 
Fair comment, Tbleken. But you say you have already answered the question. Would it be a good idea to post a link here to your answer? That way, anyone with a similar problem who finds this thread will know where to look for the answer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Maybe my previous given question is quite confusing, but i' now tried to simplified into below for you all to understand.

vl_file = "C:\test.dbf"
vc_file = "C:\test123.dbf"

use (vl_file) in 0 again alias tst

erase (vl_file) ==> It should not be able to delete because it is currently in use.

use in select('vl_file')
use (vc_file) in 0 again alias tst

erase (vl_file) => it work when i tried in fox command prompt, but it won't able be working in Fox's .PRG File.Why?

Hope someone could help me out on this problem because I can't maneged to erase those unwanted system file in use (example like sys(3).dbf).
 
Hi Tbleken,

>> I'm not sure I agree with Tbleken about posting in different forums.

I too agree with Mike, because "Creating a new thread to ask a question" is my last resort to solving my "RIGHT NOW" issue, so therefore I'm looking and asking for an immediate as possible answer. Why, because I'm stuck and cannot move forward. Get help from whoever.

>> numerous cases where people give answers not in order to really help, but to "impress" people by showing that a simple problem can be solved in many different ways. Helpful? No, not the least.

Also for me there is no such thing as "too many replies" whether they are trying to impress or not with the many varied solutions. That causes me to "think outside the box", which could lead me to an entirely different solution not previously envisioned. So, for me, more ideas equals more options equals more solutions.

And if I see a question that I've answered elsewhere, I'd normally ignore it, but then I should do as Mike suggests, "provide a link to my answer" therefore visitors to this page benefits.

Just my 2 cents worth,
Stanley
 
Koklimabc,

Your code is still confusing. You can state your problem much more simply, like this:

Code:
use in select('vl_file')
erase (vl_file) => it work when i tried in fox command prompt, but it won't able be working in Fox's .PRG File.Why?

All the other opening and closing of files is irrelevant.

So, the question boils down this. You have apparently closed vl_file, but when you try to erase it in a PRG, VFP won't let you do that.

There are many possible reasons for this. The file might be open in a different data session. Or in a different application. Or in a different instance of your application. Or VFP might have opened it "behind the scenes" for some reason.

I don't know the reason that you can't erase the file. I do know that being able to explain your problem clearly and simply is a pre-requisite to finding the solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Another question i need to ask you all because I still confused for certain work area mighty be.

use in select('tmpcur_')
use dbf('tmpcur') in 0 again alias tmpcur_ exclu
*use in tmpcur ==> what is line work in exactly? I concluded myself guess it will constantly open the database connection in current work
==> area. Without this it will happens with error "File is open in another work area" whenever I tried to select alias
==> in next line.If I never put this, I cant pack after delete it and I must make sure it truly opened always so far
when apply alias tmpcur_ into grid's recordsouce.

sele tmpcur_
dele all
pack
 
use in tmpcur closes tmpcur.

USE always uses a workarea and opens what you specify BEFORE the IN clause of the command and close whatever is in the workarea you specify BY the in clause. So the IN clause specifies where to open something and whatever is open there of course is closed. In can specify a workarea number or alias name. USE IN tmpcur therefore does not address tmpcur.dbf, it addresses the workarea alias tmpcur and it opens NOTHING, as you don't specify anything before the IN keyword, so indeed it means USE nothing IN workarea alias name tmpcur.

Any USE something IN 0 works in the next empty workarea (which has this "meta" workarea number 0) and therefore does not close anything, but USE in aliasname is the inverse use of the IN clause, it specifies a certain workarea to CLOSE that aliasname. As a result, you can do a non operation, if you simply write USE IN 0, you specify the empty workarea 0 and nothing to open, so you neither open nor close anything. But the main concept of USE always combines opening and closing, we just very seldom have the case of closing something and opening something else at the same time, but it's possible to eg USE orders in customers, which would open the customers.dbf in the workarea name customers, that workarea in the end will be renamed to orders. I would actually prefer the VFP language to have seperate commands for opening and closing a table, but that's how it is.

If you have something open as alias tmpcur, even the first line will fail:
use dbf('tmpcur') in 0 again alias tmpcur_ exclu
This would mean you open up whatever tmpcur is in another empty workarea (0) again, and you want to open it exclusive. You can't open something exclusive, if it's already open. The only way it may work, if only you have it open exclusive already, but that's not a good excuse for trying that way.

If you have a dbf open shared and want to try to get exclusive access the only thing to do is
Code:
SELECT tmpcur
USE DBF() EXCLUSIVE
This will close whatever is open in the currently selected workarea and reopen it exclusive right away.

Do you work in VFP6? Then similar code is used to reopen query result cursors to be able to write to them. That's needed because VFP6 has no READWRITE clause.

The main recipe here is something like
Code:
* query data:
SELECT ... FROM sometables INTO CURSOR curTmp NOFILTER
* make the result writable:
USE DBF("curTmp") AGAIN IN 0 ALIAS curTmp2
USE IN curTmp

Now you have the result in curTmp2 writable.
There is no need for EXCLUSIVE, DBF("curTMP") will point to your temp folder anyway, and no one else has access there.

Bye, Olaf.
 
Dear olaf,

I'm in deep understand now.Thanks. BTW, i'm working VFP6.0.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top