• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Updating datasource on-the fly

Enthusiast ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

Hi,

We have a requirement to switch datasources in our application. A cloud app we are developing has a primary and secondary server and it will tell us when the primary is offline and it can call a end-point (.cfm) on our server. If this script updated our neo-datasources.xml on-the-fly with the new datasource information, would this change the DSN reliably? Would it require a server restart? Does it sound viable?

I suppose we could also put some code in application.cfc to check the database, but this means we have to change the DSN back again at some time in the future when the DSN for the primary starts working again, so perhaps some scheduled task etc? All sounds a bit too convoluted.

We could put a test in our .cfm code to see if the primary database was offline, but that's more code and it has to be in every request, which sounds a bad idea.

Any ideas appreciated.

Thanks,

Mark

TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

This is where you should be using the cf "admin API", which was introduced in CF7 but which many never have learned about. You should generally NOT be manipulating the neo xml files yourself, least of which because yes a CF restart would be needed to reload such file changes. (You also risk making a mistake in the xml.)

The whole point of the admin API is to allow such programmatic changing of the admin settings, on the fly, and especially for the sake of scripting configuration (as may be needed in spinning up containers, etc.).

Here are a few resources to get you started. Note that there are many cfc's in the API, and different methods in each. First up, check out:

Some recently added (and evolving) documentation of the CF Admin API - Charlie Arehart's Server Trou...

And the docs it points to. Then see this post from Adobe. But again it's about CREATING data sources.

Configuring Data Sources using Admin API in ColdFusion - ColdFusion

Let us know if that helps.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

I meant to say more toward the end. Where I said: "Then see this post from Adobe. But again it's about CREATING datasources."

I had meant to add more:

"So since you want to edit your dsn's, or perhaps just rename them to flip between variants, you'll want to look for methods in that datasource cfcnto help with that  So use that example merely as a general guide".

Sadly, a bug in the portal here would remove all paragraph formatting if I were to edit my last reply, instead  thus this new one. Grr.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

Hi Charlie,

Many thanks for the reply.

We have used the Admin API in the past, but I don't think it has a facility for saying "use this datasource". I recall it only creates/deletes DSNs? Please correct me.

The issue we have is that we have two connection strings. Our application stores our active DSN in an application variable, so we can change over, but we want to do it in an automated way if possible. If no one is around to make a code change, we get down-time. The question is more related to our cloud platform - I will see what we come up with.

Thanks,

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2019 Mar 05, 2019

Copy link to clipboard

Copied

Sure. Had you seen my follow up several mins after my first one? I think it addresses your question.  Let us know.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

LATEST

Hi Charlie,

the link for API documentation does not work

It must be changed to https://helpx.adobe.com/coldfusion/user-guide.html/coldfusion/configuring-administering/coldfusion-a...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation