• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SQLServerException - could not connect to the host on port 1433

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)


 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Patrick,

Check out if this thread could help you
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Patrick,
Did you ping the port ?
Check of you cud trouble shoot the sql server logs as mentioned here
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic