170

I use the following connection string in SQL Server Management Studio. It failed to connect:

mycomputer.test.xxx.com:1234\myInstance1

But the following one is ok:

mycomputer.test.xxx.com\myInstance1

So how do I specify a port number in a connection string?

1

3 Answers 3

320

Use a comma to specify a port number with SQL Server:

mycomputer.test.xxx.com,1234

It's not necessary to specify an instance name when specifying the port.

Lots more examples at http://www.connectionstrings.com/. It's saved me a few times.

10
  • 10
    Each instance must be on a separate port, so port=instance in Sql server. I never knew this ",port" until now, though - thank you. Mar 14, 2011 at 4:35
  • 2
    @Daniel: yep, you need to specify either port or instance. Mar 14, 2011 at 4:37
  • 11
    Note: instance name is ignored when port is specified. So "mycomputer.test.xxx.com\AnyOldRubbish,1234" still works.
    – gbn
    Mar 14, 2011 at 5:32
  • 1
    How does this work if the default (MSSQLSERVER) instance isn't running on 1433? Mar 16, 2017 at 15:58
  • "not necessary to specify an instance name " That was key for me. FreeTDS on Raspi will crash if you put in the instance name and a port. Never knew you could skip the instance name, and that's the only way to get it working in FreeTDS. Oct 20, 2017 at 17:31
12

For JDBC the proper format is slightly different and as follows:

jdbc:microsoft:sqlserver://mycomputer.test.xxx.com:49843

Note the colon instead of the comma.

2
  • 2
    I have turned from C# to Java, and this answer saves me. Again. Apr 3, 2015 at 1:10
  • 1
    Awesome, glad it helped. Not exactly intuitive documentation in Java for the JDBC connection string. Not sure why it's different either, which is annoying.
    – Shanerk
    Apr 6, 2015 at 17:29
4

The correct SQL connection string for SQL with specify port is use comma between ip address and port number like following pattern: xxx.xxx.xxx.xxx,yyyy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.