Avatar of mte01
mte01
Flag for Lebanon asked on

In DB Connection: Error establishing socket

Hey experts,

conn = DriverManager.getConnection(dbURL,user,pwd);

where

static final String dbURL =
    "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DBServer";
  static final String user = "sa";
  static final String pwd = "sa";

I am getting: "Error establishing socket"......any help??
Java

Avatar of undefined
Last Comment
mte01

8/22/2022 - Mon
CEHJ

Make sure the server is running on that port on the local machine
mte01

ASKER
I couldn't find the place where I could verify in Microsoft SQL Server that it is running on port 1433.......but this is what is supposed to be doing, I have just installed it with the default settings.
bloodredsun

Are you sure that that is the correct URL for the database?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
CEHJ

>>I couldn't find the place where I could verify in Microsoft SQL Server

netstat -a | find "1433"

No output means it's not running
mte01

ASKER
Yes....this is the correct URL of the DB (it's name is DBServer, the port is 1433 , and these are the username & pwd & and everything else is from the driver........)
CEHJ

And the output of the command was..?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
It's not running on port 1433...what do I do now? (I can't find where the service is from the whole netstat list)
CEHJ

As i said, if that command returns  no output then it's not running (at least not on that port)
ASKER CERTIFIED SOLUTION
bloodredsun

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CEHJ

>>what do I do now?

Start it ;-)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
mte01

ASKER
OK....so do I post a new question in the networking TA, so I can see how I can run it on port 1433??
CEHJ

>>You could also try telnetting to the server on that port ...

No need if the command i gave earlier has been used
CEHJ

>>OK....so do I post a new question in the networking TA, so I can see how I can run it on port 1433??

You just start the server !
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
It is up & running (I can see it from its GUI interface)
mte01

ASKER
But it doesn't appear in the telnet list..........weird!!
CEHJ

Find out what port it's set to run on through the gui
Your help has saved me hundreds of hours of internet surfing.
fblack61
mte01

ASKER
I just checked it on the GUI...it's 1433.........but it doesn't appear on the netstat list.............
CEHJ

You used the command exactly as i mentioned?
mte01

ASKER
Yes CEHJ...........it didn't return anything.........& I also checked the whole list.................does it affect if I am uisng Win XP Home Edition??
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bloodredsun

Is TCP/IP running?
mte01

ASKER
Yes sure...
CEHJ

XP has a firewall but i didn't think it worked outbound. However, in general, make sure you have no firewall preventing a connection
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
CEHJ

>>make sure you have no firewall preventing a connection

... and also the creation of a socket on that port
mte01

ASKER
Yes, I made sure of that.........
mte01

ASKER
>> ... and also the creation of a socket on that port

How could I check for that??
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
& this is SP2 by the way...
CEHJ

>>How could I check for that??

The crude way would be to stop any running firewalls
mte01

ASKER
Yes, I did that....by the way if I want to change the port what do you suggest??
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
CEHJ

I think you can do it using the SQL Server Network Utility
mte01

ASKER
I know, but what port would you suggest that we would use??
CEHJ

Well i'm not sure if it's going to solve your underlying problem but you could change it to another one that's not already being used
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
We just tried it........same problem

and  bloodredsun

I have tried all the methods mentioned in the forum link that you gave with no avail...........
CEHJ

You're not running it in a limited account are you?

1. Check the system logs for errors
2. If all fails, reinstall it
mte01

ASKER
I just re-installed it....same problem...........
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mick Barry

Open the SQL Server Network Utility and check that TCP/IP is enabled and that it is listening on the correct port.
CEHJ

What about the first two points of my last comment?
mte01

ASKER
>>objects

I checked EVERYTHING objects


>>CEHJ

I chekced both of your two comments...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mick Barry

So what protocols are enabled?
And what port is it listening on?
gnoon

mte01,

  I ever got a problem that seems to be like your case. If I enabled both Named Pipes and TCP/IP and let TCP/IP on top of the list .. I could start SQL service but nothing running on port 1433 (as I configured). If I enabled only TCP/IP on port 1433 .. I couldn't start the service and an error shown in event viewer .. the error was

Event Type:      Error
Event Source:      MSSQLServer
Event Category:      (8)
Event ID:      19011
Date:            18/1/2548
Time:            9:48:48
User:            N/A
Computer:      gnoon
Description:
SuperSocket info: gethostbyname(MSAFD Tcpip [TCP/IP]) : Error 11001.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

I thought the error telling me that SQL Server couldn't get IP Address of database server by computer name.
It's true! I couldn't ping my computer by computer name. My solution is I open file C:\WINDOWS\system32\drivers\etc\hosts and then put a mapping of computer IP and name there, then started the service again.
Of couse, it worked like a charm ... I could start the service with TCP/IP on port 1433. Then, my java app could connect to the service. Happy ending :-)

Hope my long story help you.
G noon


CEHJ

>>and an error shown in event viewer

I suggested you do that earlier mte01 - did you?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mick Barry

> I suggested you do that earlier mte01 - did you?

mte1> I chekced both of your two comments...
SOLUTION
gnoon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
Hello again guys,

Right now I don't have the computer where the problem is with me,.

>>gnoon
Although I checked the system log for SQL Server, there was no problem, but I'll do the steps that you followed (later), and I'll see what happens.
SOLUTION
Mick Barry

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mte01

ASKER
The TCP/IP protocol is enabled (in addition to other protocols that I have forgotten), and it's listening on port 1433.............
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

What happens when you take the DatabaseName out of the connection String?
mte01

ASKER
I haven't tried it, and I can't try it now because the PC with the problem is not with me..........but I tried another DB, and the problem was the same............I'll be trying it if you want later..........
CEHJ

OK
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
CEHJ

:-)

OK now?
mte01

ASKER
Well actually, my friend who had the problem on his pc (which we were working on it) decided that we would work with sql server on another pc, so he removed sql server from his pc