ColdFusion - Datasource '' could not be found - Stack Overflow

admin2025-05-01  0

Here's an interesting problem we've been having lately.

Currently on ColdFusion 2021 (hoping to migrate to 2023 in the next month or so).

Starting many versions of CF ago, we transitioned our apps to define the datasource in Application.cfc and transitioned all our <cfquery calls to not specify the datasource directly.

this.datasource = 'app_connect';

In the last few months we started occasionally getting the error Datasource '' could not be found. (automated error catching that emails the developers). It does not seem to be a constant problem because we've never had a user report a problem, the error seems to happen to random pages, and the error never seems to happen more than once in a row. But it is persistent and I'll get the error report maybe once or twice a week at random times during the day.

I think it might be tied to session time outs, but not sure why it would be a relatively new phenomena.

Is anyone else seeing errors like this? Any ideas? I can go back to specifying the datasource in the queries if that would help but would love a better solution if anyone has a better idea.

Here's an interesting problem we've been having lately.

Currently on ColdFusion 2021 (hoping to migrate to 2023 in the next month or so).

Starting many versions of CF ago, we transitioned our apps to define the datasource in Application.cfc and transitioned all our <cfquery calls to not specify the datasource directly.

this.datasource = 'app_connect';

In the last few months we started occasionally getting the error Datasource '' could not be found. (automated error catching that emails the developers). It does not seem to be a constant problem because we've never had a user report a problem, the error seems to happen to random pages, and the error never seems to happen more than once in a row. But it is persistent and I'll get the error report maybe once or twice a week at random times during the day.

I think it might be tied to session time outs, but not sure why it would be a relatively new phenomena.

Is anyone else seeing errors like this? Any ideas? I can go back to specifying the datasource in the queries if that would help but would love a better solution if anyone has a better idea.

Share Improve this question asked Jan 2 at 14:59 Stephen F RobertsStephen F Roberts 3421 silver badge11 bronze badges 2
  • Do the emails contain any other information, such as the page being run? – Dan Bracuk Commented Jan 5 at 19:56
  • The errors have the pages being run and the actual CFC that holds the queries. It isn't the same page every time. I just checked back the last 3 months of errors (41) and it does seem to hit on the home page query more often than others (10 of 41), but the other 31 were all over the place. – Stephen F Roberts Commented Jan 6 at 14:18
Add a comment  | 

2 Answers 2

Reset to default 1

Root causes for this issue might be the following things.

  1. Application Scope Persistence Issue: The "this.datasource" value is set in the "Application.cfc" and should be available throughout the application lifecycle. However if the application scope is being restarted (e.g., due to server restarts, changes in "Application.cfc", or deployment updates), the value of "this.datasource" could be temporarily unavailable until the application is reinitialized.

  2. Session/Request Scope Confusion: If the queries are somehow relying on a "Session" or "Request" variable for the datasource, it could fail when those variables are cleared or expire.This could explain why the issue is intermittent and appears to correlate with session timeouts.

  3. Race Condition During Initialization: If multiple requests hit the server simultaneously when the application is initializing or reinitializing, some requests may fail to find the "this.datasource" value if it hasn't been fully set up yet.

Some suggestions to overcome this issue:

  1. Add debugging code to your "onApplicationStart" or "onRequestStart" methods in "Application.cfc" to log whether "this.datasource" is correctly set when a request is processed.

  2. To prevent race conditions, use locking around your application initialization logic of datasource in "onApplicationStart".

     <cflock type="exclusive" timeout="5">
        <cfset this.datasource = "app_connect">
     </cflock>
    

Correct me if I am wrong, but variables with THIS scope in application.cfc will be accessible with the APPLICATION scope throughout your code outside of Application.cfc

datasource="#Application.datasource#"
转载请注明原文地址:http://anycun.com/QandA/1746111015a91820.html