SQL Connection with public IP, named instance and port number

后端 未结 4 1010
盖世英雄少女心
盖世英雄少女心 2020-12-16 19:15

I have had difficulty creating a connection string in c# that will connect to a remote SQL server using a public IP, named instance and a port number (other than 1433). Anyo

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 19:45

    Using the servername tcp:,, as documented in SqlConnection.ConnectionString:

    The name or network address of the instance of SQL Server to which to connect. The port number can be specified after the server name:

    server=tcp:servername, portnumber

    When specifying a local instance, always use (local). To force a protocol, add one of the following prefixes:

    np:(local), tcp:(local), lpc:(local)

    Data Source must use the TCP format or the Named Pipes format.

    TCP format is as follows:

    • tcp:\
    • tcp:,

    If you use the tcp:\ the SQL Browser service connection is required (port 1433) therefore is better to use the later format, with explicit port name:

    Data Source=tcp:1.2.3.4,1234;User Id=...; Password=...
    

提交回复
热议问题