Skip to content

Port used for MSSQL databases #11633

@jeffest

Description

@jeffest
  • Gitea version (or commit ref): 1.12
  • Git version: 2.22
  • Operating system: Windows 10
  • 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:

Description

The installation process assumes that the MSSQL server instance provided by the user will listen on the default port 1433. This is defined in function ParseMSSQLHostPort.
By doing so, it prevents the mssql driver from actually detecting the port automatically. This has a major impact if the db server is hosting multiple instances of SQL Server. The port 1433 is being used by the default instance and all other instances will use dynamic ports. In order to determine the correct port for a particular instance (the one supplied by the end user), the driver is querying the SQL Server's Browser service (here). But it only does that if the port is not specified ( p.port == 0 ) which never happens considering the default value of 1433.

IMHO, there should not be a default port for mssql driver if not provided by the user and the driver should be responsible for finding it.

Activity

jolheiser

jolheiser commented on May 26, 2020

@jolheiser
Member

This is the install page regarding MSSQL options:

mssql

And then after installation, when the config is loaded, the host would be parsed like so:

// ParseMSSQLHostPort splits the host into host and port
func ParseMSSQLHostPort(info string) (string, string) {
host, port := "127.0.0.1", "1433"
if strings.Contains(info, ":") {
host = strings.Split(info, ":")[0]
port = strings.Split(info, ":")[1]
} else if strings.Contains(info, ",") {
host = strings.Split(info, ",")[0]
port = strings.TrimSpace(strings.Split(info, ",")[1])
} else if len(info) > 0 {
host = info
}
return host, port
}

Port 1433 does serve as default, but only if none of the following if-else match. If you set it as 127.0.0.1:0 then it would parse the port as 0 afaik

zeripath

zeripath commented on May 26, 2020

@zeripath
Contributor

But if we change the port in line 167 to 0 then they never have to put the port in and, it will still work for those who have it on 1433... (AFAICS)

jeffest

jeffest commented on May 27, 2020

@jeffest
Author

Yes @zeripath, this is how it should work.
@jolheiser, your remark is 100% valid but it's neither intuitive or user-friendly (AFAICT)

added a commit that references this issue on May 27, 2020
6d29e9f
added a commit that references this issue on May 29, 2020
e895517
added a commit that references this issue on May 29, 2020
5911e12
added a commit that references this issue on Jul 31, 2020
6ac6461
locked and limited conversation to collaborators on Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @zeripath@jeffest@jolheiser

      Issue actions

        Port used for MSSQL databases · Issue #11633 · go-gitea/gitea