locked
How to access SQL-server through web-application using Windows credential RRS feed

  • Question

  • I have a web-application (.Net 4.5) running on one machine(server1) which needs to get data from a SQL-server running on another machine(server2). I would like the web-application to use the windows credentials from the client(userX) to log into the SQL-server. 

    I am able to connect to the SQL-server by using windows autentication in SQL Server Management studio, so userX is granted the correct privileges (I think..).

    And when using Reporting services, userX can also connect by using windows autentication.

    So, how can I set the SQL credentials programmatically to use userX windows credentials from his client machine (VB or C#)?

    If I try to set "Integrated Security=True" in the connect string, the connection try to log on the SQL-server using the IIS-account from server1, which of course fails. I get "Login failed for user "domain\client1".
    If I try to specify UserID and password (for userX) in plain text in the connect string (just for the test), I get "Login failed for user "domain\userX".

    Part of my code:

    
    Public Shared Function GetConnectionString() As String
            GetConnectionString = "Data Source=server1\dvhdb001;Initial Catalog=Reporting_db;Persist Security Info=False;Integrated security=True"
    End Function
    
    
    Private Function LoadTestdata() As DataSet
    
    	Dim conTestdata As New System.Data.SqlClient.SqlConnection(GetConnectionString.ToString)
    	conTestdata.Open()
    
    ......
    
    

    Basically, I need to find how to provide the SQL-server With userX credentials, preferably in VB.

    Regards,

    John Martin

    Monday, October 19, 2015 8:09 AM

Answers