Unable to connect to MSSQL container through TCP Proxy

I was able to build and run a SQL Server database through a Dockerfile, exposing the standard port and providing the proper build arguments but am unable to connect after setting up a TCP Proxy (since this is a Docker-based deployment and not a supported Database Service it doesn't have a connection string if I understand right). The error I first receive when trying to connect from SQL Server Management Studio is:
Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
I also receive the error:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Framework Microsoft SqlClient Data Provider)
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Framework Microsoft SqlClient Data Provider)
Is this a TLS issue? I've tried various combinations of encrypt and trust server certificate parameters but to no avail.
Solution:
if i where to use a dockerfile id use this
FROM mcr.microsoft.com/mssql/server:2019-latest
FROM mcr.microsoft.com/mssql/server:2019-latest
this would be the entire dockerfile, this one single line is all thats needed...
Jump to solution
58 Replies
Percy
Percy•14mo ago
Project ID: 664eb8d7-2ff0-44d3-a9ab-537fd41b5746
volcanicislander
volcanicislanderOP•14mo ago
664eb8d7-2ff0-44d3-a9ab-537fd41b5746
Brody
Brody•14mo ago
any reason for trying to deploy your own mysql service instead of railway's provided mysql template?
volcanicislander
volcanicislanderOP•14mo ago
MSSQL = SQL Server If it was MySQL I would've absolutely gone with a template. I'm mostly trying to avoid the pain that is Azure.
Brody
Brody•14mo ago
oh yeah sorry my bad can you link me the docker image you are using to deploy a mssql server and I will see if I can get a template up and running for you
volcanicislander
volcanicislanderOP•10mo ago
Hi Brody, sorry I forgot about this! Here is my Dockerfile:
FROM mcr.microsoft.com/mssql/server:2019-latest

ARG ACCEPT_EULA
ARG MSSQL_SA_PASSWORD

# Default SQL Server TCP/Port.
EXPOSE 1433

# Run SQL Server process.
CMD [ "/opt/mssql/bin/sqlservr" ]
FROM mcr.microsoft.com/mssql/server:2019-latest

ARG ACCEPT_EULA
ARG MSSQL_SA_PASSWORD

# Default SQL Server TCP/Port.
EXPOSE 1433

# Run SQL Server process.
CMD [ "/opt/mssql/bin/sqlservr" ]
Brody
Brody•10mo ago
does that run a windows based image?
volcanicislander
volcanicislanderOP•10mo ago
mcr.microsoft.com/mssql/server:2019-latest is an ubuntu-based image https://hub.docker.com/_/microsoft-mssql-server
Brody
Brody•10mo ago
I assume you do have the EULA and password variables set?
volcanicislander
volcanicislanderOP•10mo ago
Yes
Brody
Brody•10mo ago
can you send the deployment logs for the service? https://bookmarklets.up.railway.app/log-downloader/
volcanicislander
volcanicislanderOP•10mo ago
Connection Details
No description
volcanicislander
volcanicislanderOP•10mo ago
Error Message: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
Brody
Brody•10mo ago
screenshot of the public networking section of your service settings please
volcanicislander
volcanicislanderOP•10mo ago
No description
Brody
Brody•10mo ago
I honestly have no clue, try the other ports in the logs 1434, 1431
volcanicislander
volcanicislanderOP•10mo ago
hmm you mean like EXPOSE those ports as well in the Dockerfile, as well as TCP proxy them, then try it?
Brody
Brody•10mo ago
the expose keyword does absolutely nothing on railway, I'm talking about with the tcp proxy
volcanicislander
volcanicislanderOP•10mo ago
OK will give it a shot
Brody
Brody•10mo ago
something else that just popped into my mind, are you perhaps on a public network? they could be blocking non standard ports such as 29343
volcanicislander
volcanicislanderOP•10mo ago
I'm at home, should be ok in that regard I think? 1433, 1434, 1431 all had the same error message Error changes to: The client was unable to establish a connection because of an error during connection initialization process before login. Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to accept new connections; or there was a resource limitation (insufficient memory or maximum allowed connections) on the server. (provider: SSL Provider, error: 0 - An existing connection was forcibly closed by the remote host.) when changing connection parameter Encrypt to "strict"
Brody
Brody•10mo ago
I'm back to being out of ideas 😦
volcanicislander
volcanicislanderOP•10mo ago
I don't see anything in the logs. Oh well, appreciate your help regardless. Was hoping to make this work to save some money and headache working with Azure.
Brody
Brody•10mo ago
I'll give this a try myself when I'm home
Brody
Brody•10mo ago
it worked!
No description
volcanicislander
volcanicislanderOP•10mo ago
Nice! What did you do differently?
Brody
Brody•10mo ago
uh idk, set the three variables the image wants and connected to it with dbgate
volcanicislander
volcanicislanderOP•10mo ago
I only set two, accept_eula and sa_password. Can you share your Dockerfile? Looks like you used SQL server 2022 image?
Brody
Brody•10mo ago
i dont use a dockerfile, but i did use the latest tag
Brody
Brody•10mo ago
No description
Brody
Brody•10mo ago
No description
Solution
Brody
Brody•10mo ago
if i where to use a dockerfile id use this
FROM mcr.microsoft.com/mssql/server:2019-latest
FROM mcr.microsoft.com/mssql/server:2019-latest
this would be the entire dockerfile, this one single line is all thats needed
volcanicislander
volcanicislanderOP•10mo ago
How did you not use a Dockerfile? Is Microsoft SQL a database option now? I think when I last tried this months ago it wasn't which is why I went with docker
Brody
Brody•10mo ago
i deployed the image directly
volcanicislander
volcanicislanderOP•10mo ago
I'm guessing there is an option to do that when setting up a new project?
Brody
Brody•10mo ago
no, the dashboard doesnt let you deploy an image from mcr, but thats besides the point
volcanicislander
volcanicislanderOP•10mo ago
Lol I don't follow. How do I go about recreating what you did?
Brody
Brody•10mo ago
^
volcanicislander
volcanicislanderOP•10mo ago
But if I understand, you're saying you deployed an image directly but I can't do that bc it's an MCR image?
Brody
Brody•10mo ago
correct
volcanicislander
volcanicislanderOP•10mo ago
What can I do differently? Add that third variable? I can use latest tag as well, I'm not pinned to 2019
Brody
Brody•10mo ago
2019 works fine
No description
No description
Brody
Brody•10mo ago
are you using the dockerfile i provided?
volcanicislander
volcanicislanderOP•10mo ago
Are you thinking this is a networking thing on my end?
Brody
Brody•10mo ago
not sure, try dbgate, its free
volcanicislander
volcanicislanderOP•10mo ago
I was using Azure Data Studio to test connection previously. I'll try dbgate Alright I'll try the 1 line Dockerfile, add the missing variable you have, and connect w dbgate and get back to you
Brody
Brody•10mo ago
i omitted the variable and it still worked for me
volcanicislander
volcanicislanderOP•10mo ago
Can I also try connecting to yours and see if it works?
Brody
Brody•10mo ago
sure, but does that mean dbgate wasnt working for you either?
roundhouse.proxy.rlwy.net:39537
sa
MK$!Q5tr+LS#AZgeq6&HjFcz7Rkvma4h
roundhouse.proxy.rlwy.net:39537
sa
MK$!Q5tr+LS#AZgeq6&HjFcz7Rkvma4h
volcanicislander
volcanicislanderOP•10mo ago
Haven't got to the computer yet Starting it now While installing dbgate I was able to connect with azure data studio to yours
Brody
Brody•10mo ago
are you using the dockerfile I gave you?
volcanicislander
volcanicislanderOP•10mo ago
Yes, just updated the repo and railway redeployed Aaaand I'm connected The one-line Dockerfile vs my original was the difference
Brody
Brody•10mo ago
awesome
volcanicislander
volcanicislanderOP•10mo ago
This could be big! Railway already hosts an API for an azure SQL DB that costs the local govt I work for hundreds a month. If I can replace that DB and colocated it with the API on railway, thats a financial and security win to me Thanks a bunch man, really appreciate your help
Brody
Brody•10mo ago
if only railway supported deploying images directly from mcr deploying a database from a repo just sounds ugly even if its using the same image in the end
volcanicislander
volcanicislanderOP•10mo ago
Yeah I feel ya, a repo for one file with one line to create a DB haha
Brody
Brody•10mo ago
but the dashboard only supports deploying images directly from dockerhub, ghcr, and quay
Want results from more Discord servers?
Add your server