"Server" vs "Data Source" in connection string
Solution 1
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
Solution 2
... 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
Solution 3
They are synonymous - you can use either one.
That is - as far as the framework is concerned, they are the same.
Solution 4
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(.)(.);
nawfal
You should accept the answer if it helped you by selecting the green tick mark on the top left of the answer. That's the encouraged practice at SO. Not only it helps future visitors, it encourages users to answer your questions. You should post what you have tried and tell us where you're stuck. That gives us more detail, and we can quickly give an answer by copy-pasting the code with minor modifications. Questions like I-need-this,-give-me-code doesnt work in SO. In the current format the question will be closed. You may read http://stackoverflow.com/faq additionally before posting. Do a good search on SO to ensure you're not asking a duplicated question, or else your question will be closed. Quick tag search
Updated on September 27, 2021Comments
-
nawfal over 2 years
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?
-
DonkeyBanana over 6 yearsI'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?
-
bytedev over 5 yearsBegs the question, why has Microsoft created equivalents...? (except to confuse us :-))
-
Damien_The_Unbeliever over 5 years@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.
-
Click Ok about 4 yearsKonrad, 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.
-
Konrad Viltersten about 4 years@ClickOk Might be, might be... You got it, though, so... :)
-
Brian Lacy about 4 yearsIt 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 thelocalhost
value and ignore the192...
value. -
Joshua K about 3 yearsthis makes it easy to copy, paste, grok, filter, and parse connection strings. This is a great answer!
-
Konrad Viltersten about 3 years@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?
-
Joshua K about 3 years@KonradViltersten docs.datadoghq.com/logs/processing/parsing/?tab=matcher