Wednesday, March 5, 2008

An error has occurred while establishing a connection to the server.

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I've seen this one before but it seems like the reasoning is different every time. This time, the error showed up because the computer was restarted. Since SQL Express was running before, I assumed that something wasn't started, and that was correct. To fix the problem, I had to start SQL Server (SQLEXPRESS) in the Services. Then, I changed the properties so it wouldn't happen again. Here's how I did it.

1. Go to Start | Control Panel
2. Double click on Administrative Tools
3. Double click on Services
4. Sort the services by name, this just makes it easier.
5. Find SQL Server (SQLEXPRESS). Look to see if the status is started or not. Hopefully, it isn't so this will fix the issue.
6. Highlight SQL Server (SQLEXPRESS), right click on it and choose Start. This will start it up.
7. Test it to make sure everything works by trying to connect to the database with Microsoft SQL Server Management Studio.
8. If this didn't fix it, something else may be wrong.
9. Now, to prevent this from happening again, right click on SQL Server (SQLEXPRESS) again and choose properties.
10. In the startup type drop down box, choose "Automatic"

No comments: