178

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

340

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.

Sign up to request clarification or add additional context in comments.

10 Comments

Each instance must be on a separate port, so port=instance in Sql server. I never knew this ",port" until now, though - thank you.
@Daniel: yep, you need to specify either port or instance.
Note: instance name is ignored when port is specified. So "mycomputer.test.xxx.com\AnyOldRubbish,1234" still works.
How does this work if the default (MSSQLSERVER) instance isn't running on 1433?
"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.
|
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 Comments

I have turned from C# to Java, and this answer saves me. Again.
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.
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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.