Forums Register Login

SQLServerException - could not connect to the host on port 1433

+Pie Number of slices to send: Send
Hi guys,

I'm getting a 'could not connect to the host on port 1433' error with the below code. I've checked my URL string several times with what MS says it should be, and my Windows Firewall is off. I've ensured that MSSQLServer is using TCP 1433 and running, BUT, and I'm not sure why this is, when I do netstat, I do not see anything listening on 1433. The SQL Server process in the task manager does not match with anything from the netstat output, and the .exe (I used -anob switches with netstat) does not match up. The closest thing I see is SQL Browser listening on port 1434. Am I missing some important detail?

Full error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:170)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1049)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at database.Main.main(Main.java:23)


+Pie Number of slices to send: Send
Patrick,

Instead of "localhost" , try with IP "127.0.0.1". Or make sure if you have "127.0.0.1 localhost" entry in hosts file.
+Pie Number of slices to send: Send
 

Balu Sadhasivam wrote:Patrick,

Instead of "localhost" , try with IP "127.0.0.1". Or make sure if you have "127.0.0.1 localhost" entry in hosts file.



Hi Balu,

Yes, originally I had 127.0.0.1, but changed to localhost just for troubleshooting. My hosts file does contain this entry, also. Does anything else stick out to you? It seems that my connection string is OK (not sure of this, though), and that my SQL Server service may not be listening?
+Pie Number of slices to send: Send
You won't see SQL Server listening on 1433 via netstat, I think it reports the port as machinename:ms-sql-s or machinename:ms-sql-m. Do you have anti virus software running? Does it block connections?

You are trying to use integrated authentication, if you swap to SQL Server authentication can you connect?

+Pie Number of slices to send: Send
 

Paul Sturrock wrote:You won't see SQL Server listening on 1433 via netstat, I think it reports the port as machinename:ms-sql-s or machinename:ms-sql-m. Do you have anti virus software running? Does it block connections?

You are trying to use integrated authentication, if you swap to SQL Server authentication can you connect?



I didn't see AVG blocking, but I did not disable it; guess I should. I haven't tried with SQL Server authentication, because I'm having problems with it. When I create a new account which uses SQL Server auth, I can't log in as the account I just created. Strange.
+Pie Number of slices to send: Send

Patrick,

Check out if this thread could help you
+Pie Number of slices to send: Send
 

Patrick Brooks wrote:

I didn't see AVG blocking, but I did not disable it; guess I should. I haven't tried with SQL Server authentication, because I'm having problems with it. When I create a new account which uses SQL Server auth, I can't log in as the account I just created. Strange.



Have you enabled your server to accept both kinds authentication? I think out the box its Windows integrated only.
+Pie Number of slices to send: Send
 

Balu Sadhasivam wrote:
Patrick,

Check out if this thread could help you



Balu,

Yes, I have checked that thread out, and it didn't resolve the problem. This is a strange one, unless there is something wrong with my connection string and I don't see it.
+Pie Number of slices to send: Send
 

Paul Sturrock wrote:
Have you enabled your server to accept both kinds authentication? I think out the box its Windows integrated only.



Aha, I'll read up on that when I get home. I didn't spend too much time on it yesterday, becuase I was still able to log on with Windows Integrated Auth.
+Pie Number of slices to send: Send
Nope, still didn't work. I turned my AVG off, and used SQL Server authentication, which I allowed this evening. I still get the 'connection refused' error. When I do a System.out.println(url) it comes out as jdbc:sqlserver://localhost:1433;databaseName=MYBASE;user=test2;password=Test1234 . Any ideas?

+Pie Number of slices to send: Send

Patrick,
Did you ping the port ?
Check of you cud trouble shoot the sql server logs as mentioned here
+Pie Number of slices to send: Send
Hmm, interesting. I had to create a database app for a job at work, and with the exact same settings and connection string, I was able to get into the localhost database, which is what I was trying to do on this laptop. No biggie, as it was more a test from this laptop than anything else, but it would be nice to know what the problem is.
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 35914 times.
Similar Threads
Exception during connecting to sql server2005
TCP/IP connection to the host localhost, port 1433 has failed
connection to mssql server database
Trouble Connectiing
SQL Database to Java using JDBC
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:08:35.