1

The scenario: SQL Server 2014 Developer with default settings and connection port (1433), C# with Entity Framework 6.

Using SQL Server with EF6 in my C# app, the following connection string works like a charm:

Data Source=localhost;Initial Catalog =...

But this connection string fails:

Data Source=localhost,1433;Initial Catalog =...

Yes, this is the correct port.

Snooping around in the configurations of SQL Server I found a solution by activating the TCP/IP protocol, but, since it's the default port, isn't it supposed to work just like the other connection string without the port? Even with the TCP/IP deactivated (which is the default)?

Thanks!

5
  • @lad2025 You do specify it with a ,, not a :. Commented Sep 17, 2015 at 14:57
  • 2
    It might be the case that it's communicating using named pipes in the first instance, but in the second instance since you're specify a port it's forcing it to use tcp/ip. Commented Sep 17, 2015 at 15:00
  • 1
    A client can't connect even to localhost if TCP/IP isn't enabled. localhost by itself worked because a different protocol was used, most likely Shared Memory. Only Shared Memory is enabled by default, which allows connections only from the local machine ie localhost. Commented Sep 17, 2015 at 15:12
  • That´s right, people. Changing the localhost to an IP address prevents it from working too. The TCP/IP protocol is required for non-shared memory access. Wonder why it comes deactivated, maybe it´s default for the Developer version of SQL Server. Anyway, thanks! Commented Sep 17, 2015 at 17:00
  • In my experience the dev version defaults to TCP/IP disabled. Standard version does too, IIRC. Commented Sep 17, 2015 at 17:22

1 Answer 1

5

You do actually specify the port like OP does, the 2 comments are wrong. https://www.connectionstrings.com/sql-server/

The reason you had to turn on TCP/IP is that you must enable TCP/IP for the server to listen on a port, default or otherwise.

The server, if TCP/IP is on, defaults to port 1433. If TCP/IP is not on, then by definition it cannot listen to any ports.

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

1 Comment

Thanks, found out in the comments that the connection string without the port connects to the database via shared memory access, and you´re right, to listen to an specific port or even connect from another host, the TCP/IP protocol (that is used when the port is specified) has to be activated.

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.