2

I have just been assigned an inherited coldfusion project. The developer dropped everything and left. Can someone point me to a good post or explain to me how to connect to a SQL database? I am using coldfusion builder and I have ftp'ed into the files but I am not sure where to create the connection to the database. Does CF builder have a connection wizard?

Tim Joyce
  • 4,487
  • 5
  • 34
  • 50

1 Answers1

4

You don't define ColdFusion connections in code, like in other languages. You define them at the server level, using the ColdFusion Administrator, which is a web-based interface:

http://yourserver/CFIDE/administrator (you'll need the password)

What you're looking for is the "Datasources" option on the left. The exact parameters you'll use will vary by database driver of course, but the options should be familiar, if you've defined datasources before in languages like PHP or C#.

Then you create a query like so:

<cfquery name="myRecordsetName" datasource="myDatasource">
    select somecolumn from sometable
</cfquery>

(CF 9.0+ you can omit the datasource parameter and define in Application.cfc).

Then you can work with the recordset in a number of way (loop over output, etc)

Billy Cravens
  • 1,643
  • 10
  • 15
  • Thanks Billy, gonna dig into this now. – Tim Joyce Nov 15 '11 at 18:40
  • Although it's beyond the scope of this question, note that it is possible to create datasources programatically - http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf364104-7fcf.html in CF9+ – Antony Nov 16 '11 at 09:58
  • Antony - True, though I get the feeling Tim is coming from other languages, where you typically define connection strings within the context of your application, whereas ColdFusion abstracts it above the app (even if you're accessing the Admin API as you mentioned - I don't think that would ever be a good idea inside of an app, since you'd be exposing your Admin pw) – Billy Cravens Nov 18 '11 at 18:29