none
Connection String for Windows Domain Account RRS feed

  • Question

  • Hi,

    I'd like to pass a Active Directory UserId and password in a connection string,  

    Without using Trusted_Connection=True. But I can only get a successful login for a SQL login, a Domain account with proper database permissions always fails.  Is it possible to pass a Domain Account and password in a connection string?

     

     

    This fails for a domain account but works with a SQL login.  

    Try

    SqlConnection1.ConnectionString = "Server=servername;Database=MyDatabase;User ID=corp\userId;Password=xxxxxxxx;Trusted_Connection=False;"

    SqlConnection1.Open()

    MsgBox("Connected", MsgBoxStyle.Information)

    Catch ex As Exception

    Console.WriteLine(ex.Message)

    MsgBox("Not Connected", MsgBoxStyle.Critical)

    Finally

    SqlConnection1.Close()

    End Try

     

    Thanks,

    Greg

    Monday, June 4, 2007 7:34 PM

All replies

  • It will not work unless SQL Server has all the users created with the same user id and password. When SQL Server uses Windows Authentication mode then you cannot pass user id and password from Windows at all. But you could do it if you are using SQL Server authentication mode, but in this case all the users have to be created in SQL Server prior connecting to it.

    Tuesday, June 5, 2007 11:21 AM
    Moderator