Solving error connecting to SQL Server from ColdFusion on Localhost
Note: This blog post is from 2006. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.[Updated a few times since 2006, to correct some minor changes in the tools involved or links offered.]
Are you getting the error, "Connection refused" or "Error establishing socket to host and port", trying to connect to a SQL Server database implemented on your own machine, when trying to call to it from an application (such as ColdFusion), using localhost and port 1433? There may be a simple explanation and solution, as I show here.
(And the issue discussed here could affect calls to SQL Server if implemented on a machine separate from your app like ColdFusion. Then again, THAT problem may just be about a need to open a hole in your firewall to allow the SQL Server port to be accessible from the CF server. Still, make sure the problem and solution below isn't the originating problem.)
The short answer is that you may need to simply enable tcp/ip as a supported protocol in your SQL Server, or tweak an aspect of it:
Open the "SQL Server Configuration Manager" in SQL Server, then choose "SQL Server Network Configuration", and its "Protocols For [yourserver]" option. Open it and ensure that TCP/IP is enabled as a protocol. If not, enable it, and restart SQL Server. For the official MS docs on this, see it discussed in this related topic.
(In some versions, where you don't readily find that Configuration Manager, see my discussion below under "The solution" for other ways to get to that feature.)
And if that TCP/IP protocol IS enabled, then right-click on that TCP/IP option, choose "properties", then its "IP Addresses" tab, and among the listed features, check if "ipall" (among the last in the list) has the port set to 1433 (or whatever is your SQL Server port), then restart SQL Server. More detail below. If you don't want to enable the "ipall" option, check the other entries to find the IP you're using (which may be 127.0.0.1 or ::1, if using "localhost" for the "server" you're telling CF to connect to), and ensure both that it's "enabled" and that its "tcp port" option is set to 1433. Then restart SQL Server and verify the DSN again.
Note that if it's still "not working" after you make these changes, do make sure you don't see a different error, like "Cannot open database "yourdbname" requested by the login. The login failed." :-) That just means you have a new and different problem to solve, now that this one is resolved. More on that below.
The rest of this entry explains additional details, such as how to find and make that change, what specific errors you get, and how I found the information, in case any of it helps others.




