Connecting to Microsoft SQL Server



To see a list of SQL Server versions that ColdFusion supports, go to www.adobe.com/go/learn_cfu_cfsysreqs_en. Use the settings in the following table to connect ColdFusion to SQL Server:

Setting

Description

CF Data Source Name

The data source name (DSN) that ColdFusion uses to connect to the data source.

Database

The database to which this data source connects.

Server

The name of the server that hosts the database that you want to use. If the database is local, enclose the word local in parentheses. If you are running SQL Server locally (or using MSDE), specify 127.0.0.1 for the

server name instead of the actual instance name.

Port

The number of the TCP/IP port that the server monitors for connections.

User name

The user name that ColdFusion passes to the JDBC driver to connect to the data source if a ColdFusion application does not supply a user name (for example, in a cfquery tag).

Password

The password that ColdFusion passes to the JDBC driver to connect to the data source if a ColdFusion application does not supply a password (for example, in a cfquery tag).

Description

(Optional) A description for this connection.

Connection String

A field that passes database-specific parameters, such as login credentials, to the data source.

Select Method

Determines whether server cursors are used for SQL queries.

  • The Direct method provides more efficient retrieval of data when you retrieve recordsets in a forward-only direction and you limit your SQL Server connection to a single open SQL statement at a time. This is typical for ColdFusion applications.

  • The Cursor method lets you have multiple open SQL statements on a connection. This is not typical for ColdFusion applications, unless you use pooled statements.

Limit Connections

Specifies whether ColdFusion limits the number of database connections for the data source. If you enable this option, use the Restrict Connections To field to specify the maximum.

Restrict Connections To

Specifies the maximum number of database connections for the data source. To use this restriction, enable the Limit Connections option.

Maintain Connections

ColdFusion establishes a connection to a data source for every operation that requires one. Enable this option to improve performance by caching the data source connection.

String Format

Enable this option if your application uses Unicode data in DBMS-specific Unicode data types, such as National Character or nchar.

Max Pooled Statements

Enables reuse of prepared statements (that is, stored procedures and queries that use the cfqueryparam tag). Although you tune this setting based on your application, start by setting it to the sum of the following:

  • Unique cfquery tags that use the cfqueryparam tag

  • Unique cfstoredproc tags

Timeout (min)

The number of minutes that ColdFusion MX maintains an unused connection before destroying it.

Interval (min)

The time (in minutes) that the server waits between cycles to check for expired data source connections to close.

Disable Connections

If selected, suspends all client connections.

Login Timeout (sec)

The number of seconds before ColdFusion times out the data source connection login attempt.

CLOB

Select to return the entire contents of any CLOB/Text columns in the database for this data source. If not selected, ColdFusion retrieves the number of characters specified in the Long Text Buffer setting.

BLOB

Select to return the entire contents of any BLOB/ Image columns in the database for this data source. If not selected, ColdFusion retrieves the number of characters specified in the BLOB Buffer setting.

LongText Buffer

The default buffer size, used if Enable Long Text Retrieval (CLOB) is not selected. The default value is 64000 bytes.

BLOB Buffer

The default buffer size, used if the BLOB option is not selected. The default value is 64000 bytes.

Allowed SQL

The SQL operations that can interact with the current data source.

Validation query

Called when a connection from the pool is resued. This can slow query response time because an additional query is generated. Configure the validation query just before restarting the database to verify all connections, but remove the validation query after restarting the database to avoid any performance loss.

Settings for the Northwind sample database

Previous versions of SQL Server included a sample database named Northwind. Establishing a connection to the Northwind database can help you learn ColdFusion while using a familiar database.

To establish a connection to the SQL Server Northwind database, set up the database in the SQL Server Enterprise manager and in the ColdFusion Administrator.

Set up the database in the SQL Server Enterprise manager

  1. Expand the server group.

  2. Expand the server.

  3. Under the Security folder, right-click on Logins.

  4. Select New Login.

  5. Select Windows Authentication or SQL Server Authentication settings.

  6. Select the Northwind database, and specify the language.

  7. Ensure that the database server is using mixed authentication. While in Enterprise Manager, right-click the server, select Properties > Security and then select the Security tab. Ensure that the SQL Server and Windows options are clicked.

  8. Click OK.

Set up the database in the ColdFusion Administrator

  1. Open the ColdFusion Administrator.

  2. Click Data & Services > Data Sources.

  3. Type northwind in the Data Source Name field, and select Microsoft SQL Server in the Driver drop-down list.

  4. Click Add.

  5. Type Northwind in the Database Name field, 127.0.0.1 (or the database server IP address) in the Server field, and 1433 in the Port field.

    Note: Do not specify a user name or password when defining the data source.
  6. Save the data source.

Troubleshooting SQL Server connections

If you are having trouble establishing a connection to SQL Server, review the following considerations:

  • If you installed SQL Server using a server name other than the default, use your chosen domain\servername wherever there’s a reference to (local).

    The following situations can cause a Connection Refused error:

    • If you specified authentication information in SQL Server, ensure that you have not defined a user name and password in the ColdFusion data source.

    • You are running a connection-limited version of SQL Server and the request exceeds the limit for TCP/IP connections.

    You can prevent this exception by setting the Limit Connections and Restrict Connections To options in ColdFusion Administrator on the Advanced Settings page for the data sources, and specifying a number less than the SQL Server maximum.

  • SQL Server does not enable the TCP/IP protocol. This problem can happen when SQL Server is on the same computer as ColdFusion. To fix this problem, perform the following steps:

    1. In SQL Server Enterprise Manager, right-click on the name of your SQL Server and click Properties.

    2. Click Network Configuration and the General Tab.

    3. Move TCP/IP from the Disabled Protocols section to the Enabled Protocols section.

    4. Click OK.

    5. Restart the SQL Server services.

    6. Verify your data source.

  • If you have are having trouble connecting, consider using mixed-mode authentication for SQL Server (Windows and SQL) and removing the user name and password from the ColdFusion data source.