MSSQL Login Timeout Error

Hi,

I’m VERY new to docker. This is my first experience with it. My company has Docker and my boss wants me to deploy my python web app that I created using Dash. The web app connects to Microsoft SQL Server 2017 for my databases.

I have created an image for my app but when I try to run it I get this error:

sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

My connection in the app looks like this:

__server = 'server'
__database = 'db'
__username = 'username'
__password = 'password'
__driver = 'ODBC Driver 17 for SQL Server'
__password = urllib.parse.quote_plus(__password)
__driver = __driver.replace(' ', '+')
__connection_string = fr'mssql+pyodbc://{__username}:{__password}@{__server}/{__database}?driver={__driver}'

Here is also my Dockerfile and docker-compose.yml (mainly things I got from my boss and the internet.)

FROM python:3.10-slim

RUN mkdir /app

RUN pip install pipenv

COPY Pipfile* /tmp/

RUN cd /tmp && pipenv requirements > /app/requirements.txt

RUN cd /app

WORKDIR /app

RUN pip install -r /app/requirements.txt

RUN apt-get -y update && apt-get install -y curl gnupg

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

# download appropriate package for the OS version
# Debian 11
RUN curl https://packages.microsoft.com/config/debian/11/prod.list  \
    > /etc/apt/sources.list.d/mssql-release.list

RUN exit
RUN apt-get -y update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17

COPY . .

CMD [ "gunicorn", "--workers=6", "--timeout=100", "-b 0.0.0.0:8000", "app:app" ]
version: "3.10"
services:

  web:
    build: "."
    command: >
      gunicorn -b 0.0.0.0:8000
        --reload "app:app"
    ports:
      - "8000:8000"
    volumes:
      - ".:/app"

The Docker version I have is 19.03.4. I also can’t ask my boss because he’s out of the country for three weeks. He’s also not super well versed in web apps anyways.

Any help/guidance/direction would be greatly appreciated!!

Can you tell us why you think the error is caused by Docker? Does that SQL server is running in a Docker container?

I would try to find out what that error message actually means. Then we can find out how it can be solved if the cause is Docker.

By searching for “mssql login timeout expired” I found this:

I hope it helps

PS.: I am going to move the topic to “General discussions” category since the issue has nothing to do with Docker Hub.

I have been looking and can’t find anything that either works or I understand enough to know where to begin. Total newbie here. I don’t know if it’s a docker issue, I just didn’t know if there was something inherently wrong with the setup that could be causing it.

I don’t see anything that is Docker related and could cause this issue. It doesn’t mean that it is not Docker related but nothing indicates that.

I also had an other question. Can you answer that?

One thing that you can do is try to ping the sql server from the container and from the host. If ping is not allowed, try telnet

telnet SQLSERVERHOST_OR_IP 1433

If the connection works, then the problem must be the driver or another parameter.
Try the solution from stackoverflow that I linked in my previous post. Make sure the driver name is correct.

You can also try to run sqlcmd in a container to test the connection to the remote SQL server.

So the server connection is in the app which is in the image. But I can’t get the container to run because of the login timeout. If that’s your question.

I asked about the SQL server that you want to connect to. I am not sure what you mean by the server connection being in the app.

Oh no the server itself is not a docker container. Do I need to make it one?

Part of me is wondering if it has to do with permissions for my company…otherwise not sure why it wouldn’t connect. The app itself works fine locally.

No, you don’t.

So it works with the same parameters connecting to a local SQL server or connecting to the same SQL server that you want to connect to now?

It works connecting to the same server.

I went down a rabbit hole and found a way to locate my server IP address for the database and I think that will help. I’m going to attempt that. Meanwhile I’ve got to integrate into a docker-compose. I’ll report back if it fixes it!