5

I'm learning Java EE, and I'm trying to open a connection to my SQL Server database running on a Docker image. I obviously get the

Cannot create PoolableConnectionFactory (The TCP/IP connection to the host localhost/DB_DEMO, port 1433 has failed.

With

docker ps -a

I get 0.0.0.0:1433->1433/tcp under "Ports" for my SQL Server image.

I know that we can use SQL Server Configuration Manager to allow TCP/IP connections, but I can't seem to find how to install it without installing the full SQL Server suite.

So, is there a way to enable TCP/IP on my SQL Server running in a Docker container? Or something I don't get in the whole "TCP/IP" thing?

EDIT [SOLVED]: I get this error with this url (Microsoft docs said 1433 is used by default if port isn't specified):

url="jdbc:sqlserver://localhost/DB_DEMO"

It worked using the {property=key} format:

url="jdbc:sqlserver://localhost;databaseName=DB_DEMO"

I've been doing too much tweeking at once while going back and forth these two formats, and my bad, I thought the problem wasn't there (I took the server/DBName format from a a documentation though). Lesson learned!

Like Mark Rotteveel replied, the TCP/IP is certainly enabled by default on the Docker image anyway.

JoRiviera
  • 51
  • 1
  • 4
  • 1
    That looks right. What does `PS C:\> test-netconnection localhost -Port 1433` display? What's your JDBC URL? It should look like `jdbc:sqlserver://localhost:1433;integratedSecurity=true. . .` for the Microsoft driver. – David Browne - Microsoft Mar 12 '21 at 19:21
  • Shows us how you launch the docker image, and shows us your connection string. As far as I know, TCP/IP is enabled by default for the SQL Server Docker image. – Mark Rotteveel Mar 13 '21 at 07:20
  • Please edit the question to include your JDBC connection URL. The error fragment `host localhost/DB_DEMO` suggests that the URL is not correctly formatted. – AlwaysLearning Mar 13 '21 at 14:29
  • Thanks @DavidBrowne-Microsoft & @AlwaysLearning, I indeed changed the url to the format prescribed in the Microsoft docs. It didn't work with the `integratedSecurity` property, apparently it requires some extra settings I probably don't need for my learning purpose here. @mark-rotteveel Indeed it's probably enabled by default. My classmates using the full SQLServer installation had to go through enabling it for the connection to open. – JoRiviera Mar 14 '21 at 11:11

0 Answers0