FireworksColdFusionDreamweaverFreehandFlashMXHome
Past Week's New Content

Latest Free Content
View All
Free Content
Accessibility
CMX Learning Guides
Hosted by enterhost

How do you globally change your DSN?

Knowledge Base

Posted by Lawrence

For security reasons, before you take your site live you should change your DSN to something unique to your site and not easy to guess. Here are a couple quick and easy ways to do it.

For security reasons you need to be absolutely sure that your application’s DSN is unique. This is especially true if you are using a commercial application or extension.

To change the DSN in your application from the default name to a new one you use Dreamweaver MX's very powerful global search and replace. Here are the steps.

  1. MAKE A BACKUP of your site. (I shouldn't have to remind you to do this should I? :-))
  2. Open any one of the files that has a recordset on it. 3. In Code view, find a and select this text: - datasource="DfaultDSN"> -
  3. Now right click and choose "Find and Replace"
  4. In the "Find In" dialog box select "Entire Current Local Site"
  5. The "Search For" dialog box should be set to "source code"
  6. In the "replace With" dialog box put you new DSN like this - datasource="NewDSN">
  7. The ignore whitespace difference should be checked.
  8. Hit the "Replace All" button.

There you go. You are all safe and secure. Doing it this way only take about 5 minutes as opposed to trying to do it page by page. Which would drive you nuts in short order. Now, if you are using CFMX, there’s a new feature that makes this even easier!

First open you Application.cfm file and set a DSN variable name. We will declare it in the “request” scope so it will be available to all files, even nested Custom Tags. Do this like so…

<cfset request.MyDSN = “YourActualDSN”>

Now in DWMX go to your “Bindings” panel and click the + and select “Data Source Name Variable” from the dropdown menu. In the “Variable Name” field enter the variable name you created in your Application.cfm file (request.MyDSN). Finally, Select the actual Data Source from the dropdown.

From now on you will choose the DSN Variable when you create a Record set and your DSN will look like this in your cfquery…

<cfquery datasource=<cfoutput>#request.MyDSN#</cfoutput>

Now all of your DSNs will be called dynamically and you need only change the DSN in your Application.cfm page and it will be changed site wide! Is that cool or what!