Page 1 of 1

Selecting an ODBC Database at runtime

Posted: Sat Aug 14, 2010 2:10 pm
by rolly
I struggling a little to come to terms with exactly how to select different external ODBC databases at runtime under Linux (I am not sure if this differs at all on windows, but I am using RH Linux).

The simplest scenario is this:

I have two Jade systems, one is dev and the other prod. I have several external sql databases accessed via ODBC, also a dev and prod instance.

I step through the ODBC wizard in Jade on my dev system and point the External Database at the development SQL DB.
At some point in my development cycle, I then extract the whole dev schema in Jade and DB and load it to my prod Jade system.
What I seem to have to do now is to step through the wizard again on my prod system to point the external DB at the production SQL to get the DSN to change otherwise, I end up trying to access my dev SQL.
This all seems resonable, but what I would like to be able to do is to change the external DB at runtime depending on whether I am dev or prod.
I had put all the details necessary to build the production and dev DSN's into an INI file and tried to modify the appropriate attributes on the external DB object at run time, but this seems to produce a variety of inconsistent results.

I guess my ultimate question is "Is it possible to change the DSN of an ODBC database at runtime without stepping through the wizard, and if so, what is the process that should be followed?"

Thanks
Roland

Re: Selecting an ODBC Database at runtime

Posted: Sun Aug 15, 2010 5:30 pm
by torrie
There a method on application that will give you the ExternalDatabase instance used for the connection. (Note it's a shared transient object.) You can then set the properties and open the database prior to querying any data. For example, here's a code snippet that we used to open the SQL database used for an RPS feed. There are other methods that you can use rather than setting the connection string.

Code: Select all

zMyStagingDatabase := app.getExternalDatabase( CMS_RPS.name ).CMS_RPS; beginTransientTransaction; zMyStagingDatabase.connectionString := app.getProfileString( app.getIniFileNameAppServer, "JadeRPS", "RPSConnectionStr", null ); commitTransientTransaction; beginTransientTransaction; zMyStagingDatabase.open; commitTransientTransaction;
CMS_RPS is the subclass of ExternalDatabase that was created by the wizard when we setup the external database in Jade.

Other code then goes on to use the external database.

As you suggest, we use the INI file to store the ODBC settings etc (rather than in the database.) That way, if you restore a database from a production system into a test system, you're not likely to connect to the wrong database.

There's also an ini file setting that you may need to set if the database names are different. https://forums.jadeworld.com/viewtopic. ... tabase+ini

Re: Selecting an ODBC Database at runtime

Posted: Tue Aug 24, 2010 11:34 am
by rolly
Thanks, this was just the info I was after.

Roland