Jump to content

How to switch to a different data file?


This topic is 4199 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I use a simple 2-file separation model configuration. My primary file automatically opens the data file using a common account ID (i.e., defined in both files). Now, I'd like to be able to switch between a "production" data file and a "test info" data file. I thought this would be as easy as closing the normal file and opening an alternate copy on a different file path. But the Close doesn't actually close the normal file ... even though I'm on a layout that has no fields from the data file (no fields at all, in fact) ... and even though it executes, seemingly without error.

My script sequence is:

Go to Layout ["Neutral"]

Flush Cache to Disk

Close File ["Primary"]

Show Custom Dialog ["Close is complete"]

Open File [Open hidden; "Alternate"]

I'll mention that the user account in effect at the time of close is not a full access account ... but the script runs with full access privileges and the exact same account is used to log onto the Alternate file. Also, I've tried multiple closes, with no change in the result (the primary file remains open).

The FileMaker help on the Close function (attached) suggests that it's not a sure-fire operation.

Hopefully, someone has already been there and done this ... and can point me in the right direction.

Thanks in advance for any help.

post-81548-0-62143100-1341157672_thumb.p

Link to comment
Share on other sites

  • 2 months later...

Hopefully, someone has already been there and done this ... and can point me in the right direction.

I'd like to re-ask this question, since I've made zero progress on this in three months:

What is the proper / effective way to close the data file in a 2-file separation model database? By "close" I mean have FileMaker display something like "no data available" and NOT automatically reopen the data file when going to some layout. The GUI file must remain open, of course, with the user properly logged on. I consider this to be the half-way point to what I'm trying to achieve ... which is switching to an alternate data file.

Thanks again for any help.

Link to comment
Share on other sites

If I understand the question correctly you are trying to change the data file that the interface file is pointing to on the fly. I assume your Table Occurrences are pointing now to "Primary"? Closing the Primary file and opening the Alternate file isn't going to do any good, the Primary and Alternate both have to be defined in Manage External Data Sources. FileMaker will search for the data files in order. The problem is that if it sees the Primary file is available it won't go to Alternate no matter what is in Primary. This would probably be doable if variables were allowed in External Data Sources but they aren't.

Hopefully if there IS a way to do this someone with more experience than myself will chime in!

Link to comment
Share on other sites

If you want to have separate development and production systems then you either: have two separate servers, with files on each; or re-name the files to ensure they are unique and keep them on the same machine.

IMHO it's important to ensure that the development system cannot be ever accidentally accessed by users, otherwise there will be huge data integrity issues. Having separate servers is good, I'd also suggest renaming the development files to ensure they cannot ever be accidentally mistaken for the production system. (The development machine can quickly be used as a replacement if anything goes wrong with the production server.)

  • Like 1
Link to comment
Share on other sites

I'd like to be able to switch between a "production" data file and a "test info" data file.

Vaughan, your comments are valid, of course, for a true production environment. So, I need to clarify:

What I'm actually doing (attempting, anyway) is switching between "field data" and "test data" in an isolated test environment. I want to be able to "swap" the data file without having to exit the application, rename the files and restart the application. But regardless of my particular use, it seems that the Close File and Open File operations should work. I'm baffled that they don't and I'd like to understand why.

Thanks for your response.

Link to comment
Share on other sites

You need two sets of files

interface.fp7 and data.fp7 are the production files

dev_interface.fp7 and dev_data.fp7 are the development files

There is no way to switch between files, other than having the interface file have two separate interfaces duplicated, one for the production and one for the development data. That sounds like a lot of work.

FileMaker will automatically open a file whenever it is needed by another file. A file will only ever close completely when no other open file needs it anymore.

  • Like 1
Link to comment
Share on other sites

even though it executes, seemingly without error.

Try looking at the error code after the "Close File" script step. It does produce an error it just doesn't show it to the user.

The only way I can think to accomplish what you are trying to do is use another file which would contain a script that can close the data and ui files, move/rename your data files to change between "field" and "test" data, open the ui file again, then close the current file running the script.

Link to comment
Share on other sites

The only way that I've found to do this is to reverse the process. If you use a launcher file it can open either data file first and then the UI. Once the data file is open the UI will use that file so long as it's in the valid EDS path for the UI file. The launcher file can reference the two desired paths of the data files. Since it's already open it forces the UI to use it. This will keep you from having to move and rename files.

If the location of the UI file is known, you can use the laucher file to appear as if the application stays open and have it reopen the UI after the data file, otherwise I think you'ld need a plug-in.

Link to comment
Share on other sites

You can also list both locations in the file reference on two lines. If the first file is closed, it will look to the second line instead.

I assume you will have to go to a null layout ... a null table actually comes in handy for other things as well. Then close your data file using admin and restart your UI.

Link to comment
Share on other sites

You can also list both locations in the file reference on two lines.

Thanks, LaRetta (and everyone).

The recommendations have come full circle ... because that's what I thought I was doing ... and what I thought would work. So, maybe I have it set up wrong. Where should the two lines be? I have them both listed as Data Sources in Manage Database >> Specify Table.

Link to comment
Share on other sites

If you hover over the left top edge of a table occurrence in the graph, it tells you it's external file reference. Then go to that external file reference - list both lines there.

Edited ... you don't list them as two references ... you list two paths to same file

Link to comment
Share on other sites

I assume you will have to go to a null layout ... a null table actually comes in handy for other things as well. Then close your data file using admin and restart your UI.

I was curious to see if this could be done so I tested before posting and found that even using a null layout/table, the data file cannot be closed from the UI file, without also closing the UI file. I tried everything I could think of to make this work, even deleting the table occurrence the current layout was associated with - but attempting to close the data file (after the UI file referenced it), via a script in the UI file would not work.

The only way that I've found to do this is to reverse the process. If you use a launcher file it can open either data file first and then the UI. Once the data file is open the UI will use that file so long as it's in the valid EDS path for the UI file. The launcher file can reference the two desired paths of the data files. Since it's already open it forces the UI to use it. This will keep you from having to move and rename files.

If the location of the UI file is known, you can use the laucher file to appear as if the application stays open and have it reopen the UI after the data file, otherwise I think you'ld need a plug-in.

This sounds like a cool trick - I didn't know that would work. I think this is the way to go.

The recommendations have come full circle ... because that's what I thought I was doing ... and what I thought would work. So, maybe I have it set up wrong. Where should the two lines be? I have them both listed as Data Sources in Manage Database >> Specify Table.

It doesn't sound to me like you've tried using the launcher file - adding both lines the the Data Source is only half the process.

  • Like 1
Link to comment
Share on other sites

If you hover over the left top edge of a table occurrence in the graph, it tells you it's external file reference. Then go to that external file reference - list both lines there.

Edited ... you don't list them as two references ... you list two paths to same file

Sorry to be so persistent on this ... but I see:

Source Table:

Data Source: (a database name)

Source File: (a filewin:/path)

File Access Protection:

Where (other than the Manage Database >> Specify Table) do I specify the second source file?

Link to comment
Share on other sites

File > Manage > External Data Source

The first line currently would be the local served Data file. If you want FM to check development Data first, list it first and put the local access second.

Heck, as last resort, you can even open the UI, change the external source, save it, close FM, open it and it'll switch to the other reference.

ADDED: But the words of caution are real ... This must be done when Users aren't in system. Why not put your UI on your desktop to work and point it to your development box for the test Data? Just remember to change it back when you serve your new version!

Link to comment
Share on other sites

Now it makes sense. If I've interpreted the "theory" correctly, going to a neutral layout and then closing the primary data source file should automatically open the secondary source ... which is exactly what I'm after. It would also explain why the primary file would never close to the point of not having any data source available to the UI.

Tomorrow (even with dansmith65's result), I'll try again to make it work. I just have to see this for myself.

Thanks, LaRetta.

Link to comment
Share on other sites

If I've interpreted the "theory" correctly, going to a neutral layout and then closing the primary data source file should automatically open the secondary source ... which is exactly what I'm after.

It may ... I am not sure. I have never tried this by just closing the Data file and leaving the UI open. It might then open the secondary source if you've changed the first line to development before closing Data. As for why a Data file won't stay closed ... it has caught me also ... even conditional format or tooltip can cause data to re-open. That's one of the reasons I like having a null table ( no fields, no records ). But upon reopening the UI it references your development file so the local served version shouldn't open because all of the table occurrences have been redirected to development.

Restarting the UI would be a small thing anyway, right? Oh, don't forget which one you're working in ... I have. :-/. Even if you use web viewer on main menu identifying the file & box, you can still forget when you are deep into it. That's one reason why I never work in production.

Link to comment
Share on other sites

I was curious to see if this could be done so I tested before posting and found that even using a null layout/table, the data file cannot be closed from the UI file, without also closing the UI file.

You are right! In fact even from null layout, if I try to close the Data file, I get error 13 (File or Object is in use), just like you said. I thought it closed and opened immediately but if we get error then it means it never completes the task to begin with!

Link to comment
Share on other sites

Did you mean closing' via script or 'closing' (unserving) the database ? If the Data file is closed in Admin console, it won't open even if called if Auto start is set to manual in services. So after closing Data (in console), switch the paths in the UI. After you exit out back to layout, it should then reference the alternate file. In theory, LOL. I wish you the best with it. :-)

Link to comment
Share on other sites

K1200, you're profile says you're still using FMP11 so this applies to 11. I don't know how 12 will react.

You don't need to change any settings, i.e. your External Data Sources (EDS). This is something that I've had to deal with on my own with a pseudo-DSM solution. Even if you decide that you want to go so far as to close both files then re-open them, the EDS should be set-it-and-forget-it.

I've gotten a bit confused by the thread (but it wouldn't be the first time I've been confused - and it is me) so I'll back up and restate this a bit.

K1200, you're correct about where you are entering the two files. You may want to consider using a relative path that assumes the testing file and an absolute path that assumes a live file. I put the relative path first such as:

file:myDataFile.fp7

file:C:/RealData/myDataFile.fp7

If you're looking at providing users with a real file and a play file this assures that if any accidents happen, it's more likely to happen in the play file. I'm also guessing here that you have already renamed your development files as Vaughn mentioned, and these two files are both deployed as customer files.

LaRetta's right about the way FM says it works and what would make sense but almost always, the data file does not actually close. I've had times when I was actually been able to close and reopen the file but I have no clue what the conditions are. Going to a completely blank unrelated layout doesn't work. You will get an error.

The key to the trick is knowing that the references in your UI file will go to an open file before it goes to the list as shown above. If either of the two files is already open, the UI file will use it. So if you open the desired data file first, the UI file will use the one that's open.

Depending on if your paths are known, you can run a script FROM the data file that first closes the UI file, the closes the data file. This will assure both files get closed when the user closes your solution. The problem with doing this is that you're now creating an association to the UI and if the UI gets moved, the user will get an error that you can't trap for.

If you want to leave the impression that the solution itself never closed, you will need a third, launcher file so it can close the data file then close the UI file.

This is counter intuitive and isn't made clear in any of the FM documentation I've found. I went round-and-round trying to get this to work the way I wanted and finally gave up after my forehead was swollen from banging it against the wall.

Link to comment
Share on other sites

Note that there are two script triggers called onFirstWindowOpen and onLastWIndowClose -- not onFileOpen and onFileClose. FMP will keep a file open (but not necessarily a window open) if there is a relationship to it.

Link to comment
Share on other sites

This topic is 4199 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.