August 11, 2014
Application datasources in ColdFusion
Comments
(5)
August 11, 2014
Application datasources in ColdFusion
(5)

Reproduced from original post here.

Datasources in ColdFusion have always been defined either in CFAdmin or through Admin API. This made it difficult for applications to be portable across ColdFusion servers.

CF11 brings application specific datasources to ColdFusion. With this, applications can register their own datasources (when they start) without messing with the server-wide datasources defined in CFAdmin. The datasource details can be defined in Application.cfc

Syntax:-

————

  • this.datasources.derbyds={ driver=”Apache Derby Embedded”, database= “C:/dev/ColdFusion/cf_main/cfusion/db/artgallery/”};
  • this.datasources.dsn1={“database”=”regression”,”host”=”localhostMSSQL2008″, “driver”=”MSSQLServer”, “username”=”sa”, “password”=”password”};
  • this.datasources.dsn2={“driver”=”MSSQLServer”, url=”jdbc:macromedia:sqlserver://localhostMSSQL2008; databaseName=regression; sendStringParametersAsUnicode=false; querytimeout=0; MaxPooledStatements=1000″, “username”=”sa”, “password”=”pass”};
  • this.datasources.customDSN = { “driver” = “other”, “url” = “jdbc:sqlserver://localhostMSSQL2008; databaseName=pubs; sendStringParametersAsUnicode=false”, “username” = “sa”, “password” = “password”, “class” = “com.microsoft.sqlserver.jdbc.SQLServerDriver”};

If you are using a custom driver, you can use the last syntax given above and specify the driver class.

If you are using drivers shipped by ColdFusion, you can specify the driver and the corresponding driver class will be picked up by ColdFusion.
Possible values for driver are all provided in neo-drivers.xml.

Note: If there is a server-wide datasource with the same name as application datasource, the latter will be picked up.

5 Comments
2018-08-09 15:24:03
2018-08-09 15:24:03

Hi. I am wondering where we locate the application.cfc file in order to change the datasource?

Like
2014-08-18 22:27:09
2014-08-18 22:27:09

Docs link for this feature.. https://wikidocs.adobe.com/wiki/display/coldfusionen/Application+variables

Encrypted password is not yet there.
Thie feature is mainly for making applications portable. There is no easy way to use an encrypted password while still keeping the application portable. You would have to package the decryption key as well.

Like
(1)
>
Himavanth
's comment
2022-05-27 18:09:04
2022-05-27 18:09:04
>
Himavanth
's comment

Just an update, the doc page for this feature is now at https://helpx.adobe.com/coldfusion/cfml-reference/application-cfc-reference/application-variables.html (and see detailed discussion for this in particular here or by searching for the discussion of “application-specific datasources”.)

Like
2014-08-18 10:48:56
2014-08-18 10:48:56

Sweet! Is this in the docs somewhere? Also, can I specify an encrypted password like Railo allows?

http://blog.getrailo.com/post.cfm/railo-4-1-explicit-datasources-in-application-cfc

Like
Add Comment