Data Source Authentication Before You Continue

Can I get a CF application to validate a valid database before proceeding with this request?

This is because there may be times when the database server may be shut down or updated, so an error occurs when a db-dependent query is executed.

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

Or can cfcatch work?

How can this check be performed?

Thank.

+3
source share
4 answers

onRequestStart Application.cfc Application.cfm , . cftry/cfcatch. , cfcatch, , , "".

+4

​​ . ( , ColdFusion 8), UDF, 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);

, , :

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

, , . try/catch . , .

+2

, , , . " ", , ( ..).

"" (, ), onError() Application.cfc / <cferror .../> Application.cfm .

+2

If you are worried that db might disappear, I would execute the query "SELECT 1 AS A" in the OnRequestStart handler, which runs only every N minutes. This can be done using the query caching function. I will start by executing the request every 30 minutes.

0
source

Source: https://habr.com/ru/post/1785650/


All Articles