Application-Specific Datasources

From Hostek.com Wiki
Revision as of 22:01, 27 August 2014 by Jakeh (Talk | contribs) (adding information about application.cfc dsn connection strings..~~~~)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Railo 4.1 and ColdFusion 11 added the ability to create Application-specific datasources (DSNs) within an Application.cfc file, bypassing the need to register the DSN on the server. The information below shows how you can get started using this new feature in either CFML engine.

Railo 4.1+ Application-Specific Datasources

The easiest way to get started is to have Railo's Web Administrator create the connection string for you. To do this, first create the DSN within your Railo Web Administrator and scroll to the bottom. You'll see the code to insert into your Application.cfc at the bottom of the page.
Rail-dsn-conn-string.png

After copying the code into your Application.cfc, you can remove the DSN from your Railo Web Administrator, and your site will still be able to use the datasource.

More information and examples of how to use this feature are available here: Railo Blog - Railo 4.1: Explicit Datasources in Application.cfc

ColdFusion 11+ Application-Specific Datasources

In ColdFusion 11 application-specific datasources are defined by manually creating a connection string that includes the driver, host, databse, username, password, and any connection options needed. For example, you could add code like this to your Application.cfc to create a MySQL datasource:

this.datasources.dsn1={"database"="regression","host"="mysqlserver.hostek.com", "driver"="MySQL5", "username"="mysqluser", "password"="ChangeTh1s!"};

More info can be found in the 'Enhancements made in ColdFusion 11 section of this wiki: ColdFusion Application Variables

The ColdFusion Blog also has some examples for your reference: Application datasources in ColdFusion