Hi,
I want to set my DSN dynamically, depending on the environment. have
environment.xml, defined several environments (local, prod etc) and
when I am in a local environment I want to use DSN A, in production
DSN B. Therefore in each <environment> block I have a setting
<Setting name="datasource" value="A" /> where the value for the
datasource is appropriate for that environment.
I also use Transfer and load it using the Transferloader.
Transferloader needs to have the DSN at initialisation:
<Property name="datasourceAlias">A</Property>
Now when I use Transfer, I don't see how I can tell Transfer to use
another datasource that's based ot the datasource setting that depends
on the environment?
function onAppInit is my <Setting name="ApplicationStartHandler"
value="main.onAppInit"/>
The next line in the trace shows some inner CB file (D:\www\wwwroot
\SimpleCMS\coldbox\system\frameworkSupertype.cfc) but the function
being called in this line _does_ try to get to the datasource:
But then coldbox:setting:datasources is not a setting datasource.
I want to get to the datasource here to get some data from the DB and
then put it in the Variables scope so it is accessible later on. Not
sure if this is possible at this stage of the request and if it is a
good practice...
I Request a page from domain A and app uses DSN myDSNNameA, I Request
a page from domain B and app uses DSN myDSNNameB...
Beats me why but I'm glad I got it at least working.
Marc, I’m glad you have something working for you. But if it breaks or if you have more time to play around with how it works, read this section of the environment interceptor that explains how to override configuration values.
In a nutshell, you want to declare your datasource in the configuration file and make sure that it’s working. You’d then override the values for each environment.