SQLEXPRESS database connection fails: Connection refused #4926

Closed
opened 2025-11-02 06:07:43 -06:00 by GiteaMirror · 16 comments
Owner

Originally created by @tbino5981 on GitHub (Feb 24, 2020).

Description

If I update from version 1.10.3 to 1.11.1 gitea won't start because the database connection somehow fails. I can revert to 1.10.3 again without problems, but 1.11.1 always fails. Config is not modified between version switches.
The MSSQL server is on the same host as gitea itself, the connection to MSSQL works via Sql-Management Studio from the gitea machine and from my machine.
I did whitelist port 1433 in the Firewall, but it didn't change anything.

Database part of config file:

[database]
DB_TYPE  = mssql
HOST     = <our-server-hostname>\SQLEXPRESS
NAME     = gitea
USER     = gitea
PASSWD   = <our-gitea-password>
SSL_MODE = disable
PATH     = data/gitea.db
Originally created by @tbino5981 on GitHub (Feb 24, 2020). <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): v1.11.1 - Git version: git version 2.23.0.windows.1 - Operating system: Microsoft Windows Server Version 1607 (Build 14393.3443) - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [x] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: https://gist.github.com/weezlemsneezle/898ffb2654743ca5e5417f7e6d1fb713 ## Description If I update from version 1.10.3 to 1.11.1 gitea won't start because the database connection somehow fails. I can revert to 1.10.3 again without problems, but 1.11.1 always fails. Config is not modified between version switches. The MSSQL server is on the same host as gitea itself, the connection to MSSQL works via Sql-Management Studio from the gitea machine and from my machine. I did whitelist port 1433 in the Firewall, but it didn't change anything. Database part of config file: ``` [database] DB_TYPE = mssql HOST = <our-server-hostname>\SQLEXPRESS NAME = gitea USER = gitea PASSWD = <our-gitea-password> SSL_MODE = disable PATH = data/gitea.db ```
GiteaMirror added the type/question label 2025-11-02 06:07:43 -06:00
Author
Owner

@guillep2k commented on GitHub (Feb 24, 2020):

Duplicate of #10258

@guillep2k commented on GitHub (Feb 24, 2020): Duplicate of #10258
Author
Owner

@tbino5981 commented on GitHub (Feb 24, 2020):

I am not sure that this is a duplicate. Their error is a Login Error, I get a Connection refused. I clarified the title.

@tbino5981 commented on GitHub (Feb 24, 2020): I am not sure that this is a duplicate. Their error is a Login Error, I get a Connection refused. I clarified the title.
Author
Owner

@guillep2k commented on GitHub (Feb 24, 2020):

I think it's the same cause, however. I'll reopen just in case. Sorry if I was mistaken.

@guillep2k commented on GitHub (Feb 24, 2020): I think it's the same _cause_, however. I'll reopen just in case. Sorry if I was mistaken.
Author
Owner

@cht47 commented on GitHub (Mar 2, 2020):

Confirm

  • Gitea version (or commit ref): v1.11.1
  • Git version: 2.16.5
  • Operating system: CentOS 7.6.1810
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:
@cht47 commented on GitHub (Mar 2, 2020): Confirm - Gitea version (or commit ref): v1.11.1 - Git version: 2.16.5 - Operating system: CentOS 7.6.1810 - Database (use `[x]`): - [x] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist:
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

Notice that "connection refused" is an indication that either:

  • The database URL is wrong (e.g. wrong IP address or name, or wrong port).
  • The database is not started.

If the DB is running on a Windows server, make sure the database service is set to auto-start. Make sure SQLEXPRESS is configured to listen on the provided IP address (I believe it normally won't). Make sure no firewall is set in between. Check the connection with some tool of your choice from a different computer than the server's.

If the server is running on the Linux instance, make sure you can connect using sqlcmd using the provided parameters.

@guillep2k commented on GitHub (Mar 3, 2020): Notice that "connection refused" is an indication that either: - The database URL is wrong (e.g. wrong IP address or name, or wrong port). - The database is not started. If the DB is running on a Windows server, make sure the database service is set to auto-start. Make sure SQLEXPRESS is configured to listen on the provided IP address (I believe it normally won't). Make sure no firewall is set in between. Check the connection with some tool of your choice from a different computer than the server's. If the server is running on the Linux instance, make sure you can connect using `sqlcmd` using the provided parameters.
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

@cht47 Are you getting "connection refused" as well?

@guillep2k commented on GitHub (Mar 3, 2020): @cht47 Are you getting "connection refused" as well?
Author
Owner

@tbino5981 commented on GitHub (Mar 3, 2020):

Gitea can connect using exactly the same config to the Database in Version 1.10.3.
1.11.1 throws connection refused.
The SQL-Server is running on the same host as the gitea server and I tried different Hosts like: .\SQLEXPRESS and localhost\SQLEXPRESS, all of which work in SQL Server Management Studio and in gitea 1.10.3 but not in gitea 1.11.1

I ran netstat on the Server and discovered that there was nothing listening to port 1433 (which gitea says in its logs it tries to connect to) but sqlservr.exe is definitely running and bound to different ports.

@tbino5981 commented on GitHub (Mar 3, 2020): Gitea can connect using exactly the same config to the Database in Version 1.10.3. 1.11.1 throws connection refused. The SQL-Server is running on the same host as the gitea server and I tried different `Host`s like: `.\SQLEXPRESS` and `localhost\SQLEXPRESS`, all of which work in SQL Server Management Studio and in gitea 1.10.3 but not in gitea 1.11.1 I ran netstat on the Server and discovered that there was nothing listening to port 1433 (which gitea says in its logs it tries to connect to) but sqlservr.exe is definitely running and bound to different ports.
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

That's probably because SQLEXPRESS is listening on a named pipe (shared memory), so SQL Management Studio can connect no problem. Check if this page helps. This is a longer, albeit more complete guide on troubleshooting your connection. Note: if Gitea is running on a different server, I can't see how it could connect through named pipes; it must use TCP/IP, therefore it must use port 1433 or some TCP port (1433 is the standard, however).

Note: I undestand that "it worked before", but I'm just trying to get you connected. It would help to know for example if Gitea and the database are on the same server, if you're running Linux or Windows (for the database), what database engine version and what windows version (for the database, if it's running Windows).

@guillep2k commented on GitHub (Mar 3, 2020): That's probably because SQLEXPRESS is listening on a named pipe (shared memory), so SQL Management Studio can connect no problem. Check if [this page](https://web.synametrics.com/sqlexpressremote.htm) helps. This is a longer, albeit [more complete guide](https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine?view=sql-server-ver15) on troubleshooting your connection. Note: if Gitea is running on a different server, I can't see how it could connect through named pipes; it must use TCP/IP, therefore it must use port 1433 or _some_ TCP port (1433 is the standard, however). Note: I undestand that "it worked before", but I'm just trying to get you connected. It would help to know for example if Gitea and the database are on the same server, if you're running Linux or Windows (for the database), what database engine version and what windows version (for the database, if it's running Windows).
Author
Owner

@tbino5981 commented on GitHub (Mar 3, 2020):

Gitea and SQL Server are both on Windows (same host, Microsoft Windows Server Version 1607 (Build 14393.3443)).
SQL-Server is

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) 
	Aug 22 2017 17:04:49 
	Copyright (C) 2017 Microsoft Corporation
	Express Edition (64-bit) on Windows Server 2016 Datacenter 10.0 <X64> (Build 14393: ) (Hypervisor)

TCP/IP is enabled for the Database, it can be accessed from a remote computer via network.
SQL-Server was installed with everything on default, the only change is, that after installation TCP/IP was turned on.

@tbino5981 commented on GitHub (Mar 3, 2020): Gitea and SQL Server are both on Windows (same host, `Microsoft Windows Server Version 1607 (Build 14393.3443)`). SQL-Server is ``` Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) Aug 22 2017 17:04:49 Copyright (C) 2017 Microsoft Corporation Express Edition (64-bit) on Windows Server 2016 Datacenter 10.0 <X64> (Build 14393: ) (Hypervisor) ``` TCP/IP is enabled for the Database, it can be accessed from a remote computer via network. SQL-Server was installed with everything on default, the only change is, that after installation TCP/IP was turned on.
Author
Owner

@tbino5981 commented on GitHub (Mar 3, 2020):

After looking at the Links you sent, I saw that my SQL-Server is listening on 1441 (this was not changed manually after install), if I change the Listening port to 1433 gitea 1.11.1 works.

There seems to be a problem with the Instance name to port resolution in gitea/the mssql driver

@tbino5981 commented on GitHub (Mar 3, 2020): After looking at the Links you sent, I saw that my SQL-Server is listening on 1441 (this was not changed manually after install), if I change the Listening port to 1433 gitea 1.11.1 works. There seems to be a problem with the Instance name to port resolution in gitea/the mssql driver
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

There seems to be a problem with the Instance name to port resolution in gitea/the mssql driver

But maybe you've got more than one instance running, or had at some point of time? Different instances will take different ports, AFAIK. Did you have the SQL Server Browser running?

Perhaps this SO link may shed some light about the issue.

Anyway I'm glad Gitea now works for you! 🎉

@guillep2k commented on GitHub (Mar 3, 2020): > > > > There seems to be a problem with the Instance name to port resolution in gitea/the mssql driver But maybe you've got more than one instance running, or had at some point of time? Different instances will take different ports, AFAIK. Did you have the SQL Server Browser running? Perhaps [this SO link](https://stackoverflow.com/a/17738359/225979) may shed some light about the issue. Anyway I'm glad Gitea now works for you! 🎉
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

@cht47 It's clear you're not facing the same issues as the original poster. Could you please open a separate issue, providing configuration details, error messages what steps have you tried, etc.?

@guillep2k commented on GitHub (Mar 3, 2020): @cht47 It's clear you're not facing the same issues as the original poster. Could you please open a separate issue, providing configuration details, error messages what steps have you tried, etc.?
Author
Owner

@tbino5981 commented on GitHub (Mar 3, 2020):

There may have been another instance installed, that explains the non-default port.
The SQL Server Browser is running and starting automatically.

If I query the Server Browser with this tool I get the correct port, even if I have a non-default port set

@tbino5981 commented on GitHub (Mar 3, 2020): There may have been another instance installed, that explains the non-default port. The SQL Server Browser is running and starting automatically. If I query the Server Browser with [this tool](https://github.com/adzm/ssrpc) I get the correct port, even if I have a non-default port set
Author
Owner

@guillep2k commented on GitHub (Mar 3, 2020):

So, I'll close this as a configuration problem. You can reopen and rename it to something like "MSSQL does not detect port automatically" or something like that if that's what you want, or open a separate issue. 😄

@guillep2k commented on GitHub (Mar 3, 2020): So, I'll close this as a configuration problem. You can reopen and rename it to something like "MSSQL does not detect port automatically" or something like that if that's what you want, or open a separate issue. 😄
Author
Owner

@cht47 commented on GitHub (Mar 3, 2020):

@cht47 It's clear you're not facing the same issues as the original poster. Could you please open a separate issue, providing configuration details, error messages what steps have you tried, etc.?

Thanks for the replies, I give it another shot tomorrow, going to do some more tests and provide logs, as we use it in production and devs get grumpy if they can't push, I have to clone the VM.
Normaly Gitea Update is the fastest update I can imagine ^^

@cht47 commented on GitHub (Mar 3, 2020): > @cht47 It's clear you're not facing the same issues as the original poster. Could you please open a separate issue, providing configuration details, error messages what steps have you tried, etc.? Thanks for the replies, I give it another shot tomorrow, going to do some more tests and provide logs, as we use it in production and devs get grumpy if they can't push, I have to clone the VM. Normaly Gitea Update is the fastest update I can imagine ^^
Author
Owner

@zeripath commented on GitHub (Sep 26, 2020):

We've also changed the code to allow for autodetection.

@zeripath commented on GitHub (Sep 26, 2020): We've also changed the code to allow for autodetection.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4926