158

I'm new to SqlServer, right now I have SqlLocalDb installed to work locally. Good, but I can see two connection strings typically and both works:

Data Source=(localdb)\v11.0;Integrated Security=true;

and

Server=(localdb)\v11.0;Integrated Security=true;

What exact difference is there between the two?

1

4 Answers 4

163

For the full list of all of the connection string keywords, including those that are entirely synonymous, please refer to the SqlConnection.ConnectionString documentation:

These are all entirely equivalent:

  • Data Source
  • Server
  • Address
  • Addr
  • Network Address
3
  • 19
    Begs the question, why has Microsoft created equivalents...? (except to confuse us :-))
    – bytedev
    Commented Oct 19, 2018 at 11:23
  • 1
    @bytedev - historical confluence, I believe. Most of these names started out being used in other, older DB connection "standards". When building ADO.Net, so long as there aren't conflicting usages, you may as well allow as many common ones as exist in older standards, to ease porting code. Commented Oct 19, 2018 at 11:26
  • 8
    It may be useful to know that, if for some reason your connection string includes more than one of these keywords (and the address values conflict), the last item is used; the previous values are ignored. So for example, given the connection string, Server=192.168.2.2;Data Source=localhost, the client will honor the localhost value and ignore the 192... value.
    – Brian Lacy
    Commented Mar 9, 2020 at 23:48
20

... There is no difference between Server and Data Source as they represent the same thing for SQL Server : the full name of the SQL Server instance with the syntax "MyComputerName\MyShortInstanceName" , potentially including the port used by the SQL Server instance to communicate.

Reference: http://social.msdn.microsoft.com/Forums/en/sqldataaccess/thread/7e3cd9b2-4eed-4103-a07a-5ca2cd33bd21

0
13

They are synonymous - you can use either one.

That is - as far as the framework is concerned, they are the same.

1
  • 1
    I've been googlearching for the reason for the range of equivalent keywords in the connection strings. This far, I haven't found a good explanation. I'm assuming it's due to historial reasons and users from different "worlds" coming together. Is there another reason? Commented Dec 3, 2017 at 12:18
9

My favorite set up is one that doesn't contain any spaces. In the simplest form, one has to provide four values - the URL, the container, the user and the credential.

  • server
  • database
  • user (or uid)
  • password (or pwd)

So a connection string looks like this.

server=stuffy.databases.net;database=stuffy;user=konrad;password=Abc123(.)(.);

6
  • 1
    Konrad, I think downvoters did not understand what you said. You mean, by example, its better "server" than "data source" because one word does not contains spaces. The same for "uid" instead of "user id". I think your answer is valid.
    – Click Ok
    Commented Mar 5, 2020 at 23:20
  • @ClickOk Might be, might be... You got it, though, so... :) Commented Mar 6, 2020 at 21:00
  • this makes it easy to copy, paste, grok, filter, and parse connection strings. This is a great answer!
    – Joshua K
    Commented Mar 4, 2021 at 21:09
  • @JoshuaK Thanks for the kind remark. I agree with every word except grok. Because I don't know what it means... How does one grok a string? Commented Mar 5, 2021 at 13:40
  • @KonradViltersten docs.datadoghq.com/logs/processing/parsing/?tab=matcher
    – Joshua K
    Commented Mar 5, 2021 at 14:17

Your Answer

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

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