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!

Aliased table - How do I determine the actual name of the table and the path to it?

Status
Not open for further replies.

dmusicant

Programmer
Mar 29, 2005
253
US
I have a complex function that aliases a table. At a certain point in the execution I want to know the name and path to the actual table that has been so aliased. How can I determine that? Is there a function that gives me that?
 
Code:
SELECT <AliasName>
cDBF = DBF()  && Fully pathed name of data table
cDBFName = JUSTFNAME(cDBF)  && File Name
cDBFPath = JUSTPATH(cDBF)  && Location

Good Luck,
JRB-Bldr



 
Thanks. I'd done some rooting into the Help, saw the DBF() function and several other promising looking functions. I checked out some of the others but not the DBF().

Here's the reason I'm doing this at the moment:

This app/function has its own screen. I often launch it from another screen, which is kind of my home screen (when I launch VFP, it goes to that home screen). The home screen, when launched, has no tables open, and I think that was a very good design decision. If I put the PC to sleep with VFP running and the home screen up, I can reawaken the machine and all is fine. However, the secondary app I'm referring to has a table open behind it. That was a mistake, evidently. All my tables are usually located on my NAS, and are often accessed via WIFI (I think it happens when ethernet connectivy is used as well). So, when I awaken the machine and the secondary app screen is up, if the machine was asleep long enough, I get an error... the handle has been broken, VFP can't find the table. The upshot of that is that I have to exit the secondary app to the home screen before putting the machine to sleep. Sometimes I forget. I figure the logical thing to do is to alter the secondary function so that no table is open, have it open the table when some kind of execution is called. The app is rather complex. I'm hoping that stashing DBF() in a variable and then launching the table at the appropriate moment will resolve the problem without negative consequences.
 
Dan, I think your logic is sound, but I'm not sure why you need to use the DBF() function to re-open the table. Presumably, you were able to open the table in the first place, so you must already know its name and path. If you want to access a table and you are not sure it is open, the usual technique is like this:

Code:
IF NOT USED("MyTable")
  USE MyTable IN 0
ENDIF
SELECT MyTable

If you apply that code in all processes that use the table in question, you should avoid any errors.

Also, I question the wisdom of relying on wi-fi to access a NAS. It might be fine for occasional accesses, but for a constantly-running application of this kind, I would have thought a hard wire would be essential (but I have to admit that I don't have any personal experience of wi-fi with NAS).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You're not the first reporting problems with a) Wifi and b) Hibernation. A combination of these is even less desirable.

Check out the "Binding to Windows Message events" sample in the Solution Samples that come with VFP.
binding_yoekz2.png


The two lines at the right side come from me letting the system go into energy save mode and waking it up again. This means you can react to these events.

That said it's seldom done by closing and later reopening DBFs. You'll have to save lot more settings like relations, current row in each workarea, etc. and can't prevent things happenning like automatic saving of buffers in buffered DBFs just by closing them. I'd say simple situations might be "hibernatable", but Foxpro applications are special about their internal file handling.

Nothing you can really do about as you don't get to the level of file handles in the same way you don't get at RAM memory addresses, VFP hides this from the developer like any good 4th or 5th generation language doesn't work with memory pointers any more. So whatever is not working with the reconnection to NAS etc is on the runtime, if not C++ runtime or OS level and you can only pull the plugs and replug on the level of closing and reopening DBFs, which is not so easy as it first seems. Notice there is CREATE VIEW / SET VIEW, but it also is very limited on storing the current datasession state, i.e. it does not care for current row (recno) per workarea and/or relations: Besides that closing DBFs several controls have problems, mainly the grid. One main stratgy would be using cursors for everything, that'd be best practice anyway, no matter if the backend is DBF or remote database (MSSQL,MySQL), using a three tier architecture means having a data access layer, which loads/saves data from wherever and provides it to forms as cursors only. Cursors are local temp files and their availability isn't harmed by hibernation.

Bye, Olaf.
 
Hi,

Also, I question the wisdom of relying on wi-fi to access a NAS. It might be fine for occasional accesses, but for a constantly-running application of this kind, I
would have thought a hard wire would be essential (but I have to admit that I don't have any personal experience of wi-fi with NAS).

From my experience:
- WiFi is fine with NAS ala the signal strength is high and stable (e.g. in a large open office) - absolute catastrophy if weak or flaky
- Better of course wired connections

I'd recommend to include a timer in the app which shuts it down (cf. ON SHUTDOWN) after a certain time of inactivity. Better restart the app from time to time than have to fix corrupted files.

hth

MK
 
Code:
IF NOT USED("MyTable")
  USE MyTable IN 0
ENDIF
SELECT MyTable

I have used code like that a lot in my functions, often as a hedge against a mistake. In this instance, I could but my problem with this function is that (I'm not sure about this) I think it may not be too easy to figure out what exact table is open. There's a function that opens and aliases tables. It's used for different reasons. IOW, it has multiple functions. I suppose I can add a line or to to it to stash the filename and location of the table that gets aliased in a variable (even make that PUBLIC) and refer to the variable later if needed. Yep. I'll look to that.

The wifi connection... One of them is suspect. I have one machine whose wifi connection is relatively weak compared to the others. I have actually experienced serious data corruption on one or two occasions. Fortunately I was backed up and was able to recover completely without pulling my hair out. I'm thinking I should investigate getting some kind of hardware that would strengthen the wifi connection from the router. Something in between to amplify the signal. Ethernet to that machine isn't out of the question but it would be a long run, snaking cable up from the upstairs router into the attic, through the attic to a flu, which IIRC was for exhaust from the downstairs kitchen stove. From there it would have to snake through the kitchen, against the walls. :) Doable, yes, necessary, probably not, I'm thinking. But that data corruption is scary. Also, I often experience terrible delays using Foxpro with that machine. Delays over a minute at times. I should do something.
 
Dan, I don't see the [tt]IF NOT USED() ...[/tt] logic as a hedge against mistakes. Rather, it is a way of encapsulating a process so that it doesn't need to know whether other parts of the application have opened a given table. I would have thought that was similr to the problem that you have. But of course you know your application better than I do.

Re connecting to your NAS, have you considered a system that carries data over a domestic mains electricty circuit? I'm not sure what they are called, but basically you have a little gizmo that connects from your router to a wall socket. Then you plug another device into any mains socket in the same building. That device has one or more ethernet ports to which you can connect a NAS or whatever.

I use this system in my own home office. Not because the wi-fi is flaky, but because I have a couple of desktop computers and a network printer that don't support wi-fi. It seems to work OK - and is a lot better than long cable runs between floors.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hey, Mike, that system of using the power circuitry (AC) to extend the ethernet sounds promising. I will look into that. An actual ethernet run from my router to that machine would be (I'm making a ballpark guess) something like 100 feet (~30 meters?).
 
I'm having more trouble than I'd hoped in making this seemingly simple adjustment to this function. Fortunately, I've left the original screen intact and saved a new version, which I've altered in several ways. The screen is called from a very complex PRG, which has myriad subroutines within. So, calling a differently named screen is the simple part. Getting the app to work with that altered screen is another matter! Anyway, I can get back to where things work by simply making it use the old screen.

This app is pretty old, started so simply it's not funny. It's like a seed that grew into a massive tree (LOL). To fully understand it I'd have to put a lot of code under the microscope. It's something I should do, of course. It's a very powerful app, and incredibly useful the more I use it. It's sort of a Swiss Army Knife of information maintenance.

Anyway, I'm sure it's possible to do what I'm envisioning here but I may have to be ultra patient in doing so. One thing that a programmer needs to be successful is very patient, of course.

The screen was written in FPW 2.6a, so that's what I have to use in altering it.

Edit: I'm getting close!
 
Hi,

Doable, yes, necessary, probably not, I'm thinking. But that data corruption is scary. Also, I often experience terrible delays using Foxpro with that machine. Delays over a minute at times.

Depends also on your net/router speed. If it is a 1GB router then go for the GB-Ethernet cabling solution. Ethernet over powerline usually works well in a mono phase current environment. In a dual/tri-phase current environment you'll have to add special capacitors between the phases. This must be done by your electrician (unless of course you are experienced enough to do it).

Please do also read a.o.

[link ][/url]

hth

MK
 
Well, something must be done. I just went to launch this app to find out my router model. I'm right now using a different machine, one that's 1/2 as far from the router (about 30 feet) and on the same floor (2nd floor of 2 story house). This machine utilizes 5Ghz band (the other 2.4Ghz), and it took fully 5 minutes for the screen to load! A spinning cursor for 5 minutes and it should have taken maybe a second. Normally I wouldn't tolerate that and would kill the vfp9.exe process, but this time I just waited it out, not knowing if the screen would ever appear, but it finally did.

The router is an Asus RT-N66R wireless N router. It's a pretty decent router. There wasn't any traffic over the network, at least nothing I am aware of... there should have been none. Again, the data to be accessed is on my Synology DS214play NAS. I sent Synology an email (via online request for assistance) a month or so ago, included my logs, but nothing was resolved.

Besides sending my logs, I sent this text:

"I use Visual Foxpro 9.0 with data stored on my DS214play. There are 2 3TB HDs in Raid1 with about 1GB of stored data on the NAS, only a small percent of this data is Visual Foxpro data. Frequently, the access times for data are exceptionally long. While usually I get connected to data in a few seconds, sometimes it takes a minute or more to get access. Hibernation is turned off. What is causing the super long delays."

Their reply some 6 hours later:

Synology Support said:
Hello,



Thank you for contacting Synology Support.

I think the slower access times and responsiveness might be associated with your NTP Time is Offset.

Oct 31 20:42:37 DiskStation ntpdate: Sync with time server 208.75.89.4 offset -35.431380 sec.

An offset NTP setting on the NAS can cause a number of different strange issues especially if the NAS is also joined to a domain. This can cause irregular connection behavior as well as preventing the domain to be joined at all. Under DSM > Control Panel > Regional Options, make sure this is in sync with either a public server, such aspool.ntp.org, or whatever DNS server is being used by the Domain Controller.

Feel free to reply to this email if you have any further questions or issues.

Have a great day,

Ryan
- - - -

I looked into the NTP setting idea and decided that it wasn't relevant, my settings were OK, were actually supplied by aspool.ntp.org, IIRC. Now that the app's screen has finally come up, it seems to be accessing data quickly, as if the 5 minute delay hadn't happened.

Issues such as this are very vexing, of course. I think I've even seen large delays using my ethernet connected machine, which is right next to the router. The router has a short ethernet connection to the NAS.
 
Hi,

Normally I wouldn't tolerate that and would kill the vfp9.exe process, but this time I just waited it out, not knowing if the screen would ever appear, but it finally did.

This may have left a lot of tmp files on your harddisk and you may want to "clean" your PC. Under W7: open FileExplorer - rightclick C:\ - Properties - General - DiskCleanup

Then you may want to set up a test environment. Connect your NAS and your PC/Laptop to your router via Ethernet cables, disable all WiFi and check the speed then.
Btw did you map the network folder that contains your VFP-data?

hth

MK
 
The last question is relevant i think.
In my experience VFP is much faster if you map a network share to a letter, than it is if you use the \\server method...
 
MK said:
This may have left a lot of tmp files on your harddisk and you may want to "clean" your PC. Under W7: open FileExplorer - rightclick C:\ - Properties - General - DiskCleanup

Then you may want to set up a test environment. Connect your NAS and your PC/Laptop to your router via Ethernet cables, disable all WiFi and check the speed then.
Btw did you map the network folder that contains your VFP-data?

hth

MK
I don't have the folder in question mapped (the app uses data in a certain folder and it's subfolder, which is devoted to metadata), but the drive where those folders exist is mapped to a letter.

I'll check into your suggestions above. VFP's behavior has been erratic, to put it mildly. Sometimes pretty OK. Occasionally nothing if not aggravating. Removing the laptop (Lenovo T60) from it's cradle (a mini-docking station, to which a couple of external monitors are attached), and connecting it by ethernet to the router may tell me something, but quite possibly will just leave me scratching my head. As I say, the behavior wifi connected is highly unpredictable.

Do you think it a good idea to map the actual folder where the data sits to a drive letter? There are currently two other folders that get accessed, one of them the metadata folder, and there's some data in a 3rd folder, parallel to the data folder. The app is written in such a way that any of the tables that it uses can be anywhere at all. The individual path to each table is stored in metadata. But in practice, I currently am using just two data folders, as I say, they are in parallel folders out on the mapped drive on the NAS. The NAS is set up with 4 different drives for different kinds of data. All 4 are individually mapped to drive letters, but VFP just uses one of them.
 
Hi,

From what I read this is becoming a NAS setup discussion and probably hasn't anything to do with VFP or WiFi

Hence allow me two last questions:
- Is your NAS connected to your router via Ethernet and is your router the DHCP server?
- Are you familiar with the SHARED FOLDER concept of your NAS and aware that only a SHARED FOLDER can be mapped to a drive letter? Subfolders can't. You may want to reread this topic in your DSM Help file

hth

MK

 
The Synology NAS is ethernet connected to the router, which I'm pretty sure is the DHCP server, how else could it be routing successfully to my 5 PCs and wirelessly connected printer?

I have 4 shared folders on the NAS and the Foxpro data is under one of them. All 4 are mapped to drive letters on my PCs.

Edit: Going into my router administration screen (web based), there's a radio button labeled "Enable the DRHC Server?" The No setting is selected. Clicking the Yes setting fails to change the setting to On. I opened the manual for the router and on page 38 it says:

To set up the DHCP server:

Advance Setting / LAN menu / DHCP Server

Following the directions I'm led to make that same change, from No to Yes. I tried this from a different machine, same result. For some reason I can't enable the DHCP Server.
 
Hi,

The Synology NAS is ethernet connected to the router, which I'm pretty sure is the DHCP server, how else could it be routing successfully to my 5 PCs and wirelessly connected printer?

Well, then everything should run fine. [smile]

You may still want to set up a test environment. Connect your NAS and your PC/Laptop(s) to your router via Ethernet cables, disable all WiFi and check.

hth
MK

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top