Application datasources in ColdFusion

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.

3 Responses

Leave a reply

Related