Windows Authentication

Hello everyone,
I would like to know if there is a way to prompt a user for their windows username and password, then pass those credentials to a sql server to logon. Can this be done Does anyone have any examples. Im kind of looking for the same functionality the the sql server management studio has when you open it up and it asks you to connect to a server.

Thanks in advance.


Answer this question

Windows Authentication

  • groberts1980

    You can specify in your connection-string that integrated security should be used when connecting to Sql Server:

    Data Source=sqlservername;Initial Catalog=databasename;Integrated Security=SSPI;

    And, in your application you should specify the principal-policy that you are going to use by calling this method once:

    AppDomain.CurrentDomain.SetPrincipalPolicy (System.Security.Principal.PrincipalPolicy.WindowsPrincipal);

    Then, the windows credentials of the user will be used (the user will not be prompted for his windows credentials).


  • junior.azul

    Thanks for that, that looks exactly like what I needed.

    I suppose it beggs the next question, if the user specifies that they want to log on using Sql Server authentication, do I just ask for the username and password, then use those given to me in the connection string

    Do I have to do anything else specific for using this method I mean, do I/should I encrypt the password given to me before sending it to the server If so, I would assume that there is some kind of hashing tecnique that sql server recognises

  • Windows Authentication