Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for live Data Source Name Before proceeding

Would it be ok to get a CF app to check for a valid database before proceeding to process that request?

This is because there may be instances where the database server may be down or being upgraded, hence an error comes when a db dependant request is made.

If there is no connection to the db server, the user can be safely redirected to a safe page.

Or can cfcatch work?

How can this check be done?

Thank you.

like image 955
n_kips Avatar asked Jan 15 '11 19:01

n_kips


People also ask

What is a live data source?

Live connections: Data source that contains direct connection to underlying data. relies on database for all queries and undergoes real-time updates. Real-time updates – As your viz is directly connected to the underlying data, this ensures data freshness.

How do you find the data source in Tableau?

To see the underlying data for each field in the data source, listed by table, click the View Data icon in the top of the Data pane, next to the Search field. You can open the View Data for the Data pane in Tableau Desktop only.

What is the difference between a live connection and an extract?

Live allows you real-time data while extracts are kind of batch which needs to be refreshed from time to time to get the updated data. So, in the case of live connection whatever changes will be done at the Datasource end that will be directly available to the tableau desktop.

How do you filter or get specific data from outcome of data source?

To create a data source filter On the data source page, click Add in the Filters section in the upper-right corner of the page. To create a data source filter on a worksheet, right-click (control-click on a Mac) the data source and choose Edit Data Source Filters.


2 Answers

in your onRequestStart method of your Application.cfc file or in an Application.cfm file you can run a simple query to check that the database is available. Wrap the query in cftry/cfcatch. If the query fails, you can redirect the user in the cfcatch, if it succeeds, you can be reasonably sure that your database is "alive".

like image 143
Sean Coyne Avatar answered Sep 21 '22 01:09

Sean Coyne


I've used such a check in one project. Code may looks as follows (not sure if it will work in versions of ColdFusion lower than 8), consider this sample as chunk of UDF written in CFScript:

// service factory object instance
factory = CreateObject("java","coldfusion.server.ServiceFactory");
// the datasource service
dsService = factory.DatasourceService;
// verify the dsn
return dsService.verifyDataSource(arguments.dsn);

Oh, I have even found small note in the code I wrote on my old laptop couple of years ago:

// [performance note] this server check takes 1-3ms at local PC (Kubuntu 7.10, CF8 + Apache2, Sempron 3500+, 1GB RAM)

While time looks like small I have found out that doing this check on each request is not really useful for my application. Any way I have a habit to use the try/catch extensively for errors handling. But if your datasources may cheange frequently it may have more sense.

like image 24
Sergey Galashyn Avatar answered Sep 22 '22 01:09

Sergey Galashyn