Steve,
while you're only using multiple tables from the database you connect to it's still true that in general the connection is made to the database server and it can not only have multiple tables, but also multiple databases and depending on which database system, the switch to another database can be made with an SQL command of the database server, MySQL and MSSQL have the USE command for that. It may not be a coincidence that the VFP USE command uses a DBF since DBF actually is short for DataBase File. But that's leading off-topic.
A connection can also be made only to a server and then it will depend on the server configuration and permissions of the connecting user or role to which database you are connected or whether you only connect to the server itself. In short, what you told us - Steve - is still true.
Anyway - Farzad321 - if you wonder why you don't get a direct answer on how to do this: So far we only know you make use of remote views. That's still not telling us how you connect to the database, as there are - as so often - many ways to do things in VFP.
Anyhow, I can give you an ensuring answer: It's possible to not need to change an EXE to change the database it connects to.
Even if the database choice is made in your code, currently, you can always change your code to use data - configuration data - to not have a hardcoded connection that only is to one database. In that case, you do need a code change, but one, that allows you to never need to change code again. This, by the way, is true for anything you want to make independent from the code of an EXE to not need to rebuild an EXE more often than necessary to roll out new versions.
It's not even what I was thinking about at first, but it's another way of seeing it's always possible to not need the change of an EXE. Have you never thought about configuration?
We still need to know more details to give a recommendation that fits your exact situation. I already indicated a DBC storing your remote views can also have a connection object. That's the normal case, but not the only possible way. And even if there is one, this connection object can be specified in two major ways: You can specify to make the connection via a data source name aka DSN (that's the name of a connection made in the ODBC Data Source Administrator of Windows). The other way is to specify a connection string that is specifying how the connection object actually connects to the remote database. And besides thee two ways you can also have created the views to use a DSN of the ODBC Data Source Administrator directly, without a connection object, so there could even be no connection object within your DBC. Finally, as a fourth option, you could use a remote view using the CONNSTRING option to specify the connection string.
Since we don't know that, it's impossible to give you a recommendation.
If I were you, I'd first look into the DBC that has the remote views in it and look for a connection object. You MODIFY that dbc and then look into this:
If you find a connection listed when you click that, it's likely how the remote views connect and this means it's outside of your EXE, you can change that without changing your EXE.
But even when you find such a connection, you need to make sure it is what the views use. Pick a view of your choice and inspect it, by executing:
Code:
Open Database your.dbc && if it's not already opened
? DBGetProp("viewname","VIEW","ConnectName")
In fact, if you don't know what you did yourself or inherited this application project/code, then strictly speaking you would need to check all views what their ConectName is.
If that ConnectName matches with the name of the connection object in the DBC, then the view uses that. If there is no connection object in the DBC, then open up the ODBC Data Source Administrator tool (the 32bit version of it) of Windows and see if you find that name in there, because that's where VFP looks when it doesn't find a connection object in the DBC of the remote view with that name.
Well, I would really like to have spared you all that details, and I could have, if you'd just told more from the outset. In essence, you see in any of the endpoints of all of this, you either have a connection object in the DBC, so a change of that is changing the database, or you change the connection properties within the Windows ODBC Data Source Administrator. The only case not covered yet is also the least probable case that you USE a remote view with the CONNSTRING command option. Well, in that case, it's again a code change you need to make, so the CONNSTRING itself is turned into configuration data.
In very short, I could have skipped all these details and just ask you to realize that whenever you want something to be done without recompiling an EXE, your first thought must be configuration data.
That's what you want to have to read into an application object property, a variable or a cursor, typically at the start of your application. And what you will use wherever in your code you need it. That way you avoid what's called "hardcoding" or "hardwiring" something, which has the technical debt and cost of finding all these places, changing them, and building a new EXE.
If you didn't think of configuration data in the first place, and already have 1000 places in your 1 million code lines large EXE that are that database name, you have gotten yourself into a bad situation indeed, but at least you can use a search and replace tool like VFPs own Code References to find all these places, change them once and be done with it for all future versions.
And now comes the heretical question: "Does that mean we could get down to a simple universal EXE which never needs to change itself and changes behavior just by changing configuration data?"
Of course not, even though code also can be data, configuration data has its major use for short data, like the name of a database surely is. Even the term "database driven application" is not pointing out such a construct. But you can do a lot with configuration data to have the flexibility you need to use another database, another server, another printer, anything that you can anticipate to change and won't want to address with a rebuild of your EXE to make it work again.
So, think of configuration data more often.
Chriss