Search code examples
sqlsql-serverdatabaseconnection

Can't connect to SQL Server 2005


I've installed SQL Server 2005 on my machine and now I'm trying to connect to it via SQuirrel SQL, but I am unfortunately running into problems.

When installing SQL Server 2005 I chose mixed mode for authentication and I've set up a new user account with which I'm trying to connect. I've also installed the Microsoft SQL Server JDBC Driver and I have successfully used SQuirrel SQL to connect to a remote server before.

Currently I'm trying to connect to my database by specifying

jdbc:sqlserver://localhost:1433

for the URL and selecting Microsoft SQL Server JDBC Driver.

After entering my username and password I'm getting the following error:

test: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect

with the following stack trace:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
    at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
    at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.execute(OpenConnectionCommand.java:97)
    at net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand$SheetHandler.run(ConnectToAliasCommand.java:279)
    at net.sourceforge.squirrel_sql.fw.util.TaskExecuter.run(TaskExecuter.java:82)
    at java.lang.Thread.run(Unknown Source)

One last thing, I've checked to make sure TCP/IP connections and named pipes are enabled in the SQL Server Configuration Manager.

If anyone has any thoughts on my problem I would be very grateful to hear them.


Solution

  • So after doing some more research, it turns out that my sql server was not listening to the correct port. For anyone else having this problem I recommend reading the following web page which was very useful:

    http://www.databasejournal.com/features/mssql/article.php/3689846/Using-Non-Standard-Port-for-SQL-Server.htm

    Basically you need to configure your server to always listen on a certain port (I chose 1433) and restart your server. After that it should work like a charm.