SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

When do usernames and passwords belong in connection strings

tl;dr: When using a windows or active directory authenticated id you do not put the username or password into your connection string.

Quite possibly the most common question I get is “Why won’t my login connect to the database?”. And the most common response? You’re using it wrong.

In SQL Server there are two types of ids. Windows authenticated and SQL Server authenticated. Typically you can tell the difference because windows authenticated ids have a domain attached.

[domain name]/[user name]

Note: This won’t always be the case. When creating a database level principal (a user) it is possible (in older versions of SQL Server) to create the user with a different name from the server principal (the login) and sometimes the domain name gets removed. It is also possible to create a SQL Server authenticated login/user with what looks like a domain name. So how do you tell for sure? You can either look in the GUI

Or in sys.server_principals or sys.database_principals. The type and type_desc columns will tell you what the actual type of the principal (login or user) is. You can look in BOL for all of the possible options but the ones we care about are:

  • S – SQL Login/User
  • U – Windows/AD Login/User

Here is the meat of it. With a SQL Login you have to pass the user name and password to SQL. With a windows authenticated connection you don’t! For a Windows Authenticated user/group you typically put something like Trusted_Connection (depending on the type of connection string). With Windows Authenticated principals Windows has authenticated your connection (go figure, right?). It then passes that authentication on to SQL Server without requiring it to send the password across the wire. Hence the word trusted.

For help with connection strings in general you can go to this site. There are entries for OLE DB, ODBC and more. There are also (lots and lots of) entries for non SQL Server connection strings if you need them.


My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.


Leave a comment on the original post [sqlstudies.com, opens in a new window]

Loading comments...