locked
Connection String to connect to database from WebService RRS feed

  • Question

  • This is my connection string, which the web service (hosted in IIS, running under ApplicationPoolIdentity) uses to connect to database

    <add name="AdventureWorksEntities"connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
    provider=System.Data.SqlClient;provider connection string='Data Source=TestMachine;Initial Catalog=AdventureWorks;
    Integrated Security=True;Connection Timeout=60;multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />

    When I try to access the site I am getting an exception: Login Failed for user MyDomain\TestMachine$.

    Why is IIS trying to use TestMachine to connect and not my user account (e.g MyDomain\TestUser) ? How do I specify it to use the context of the user that made the request ?



    • Edited by Shawn Dan Tuesday, October 30, 2012 11:52 PM
    Tuesday, October 30, 2012 10:46 PM

All replies

  • HI,

    Pass your account name or Machine IP address to Data Source.

    <add name="AdventureWorksEntities"connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
    provider=System.Data.SqlClient;provider connection string='Data Source=MyDomain\TestUser;Initial Catalog=AdventureWorks;
    Integrated Security=True;Connection Timeout=60;multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />


    PS.Shakeer Hussain

    Wednesday, October 31, 2012 2:34 AM
  • 1) Data Source, doesn't it refer to the machine where the Database is hosted ? I already have that specified.

    2) I don't want to put any User identity in the connection string. Which ever user accesses the site, I want IIS to use that user to make the SQL connection.

    Wednesday, October 31, 2012 3:08 AM
  • Hello Shawn,

    You have to setup the web side for  Windows authentification/impersonate mode to pass the credential of the current user to SQL Server, see e.g. Configure Windows Authentication (IIS 7) and Configure ASP.NET Impersonation Authentication (IIS 7)

    For further question you should better post to an IIS forum.


    Olaf Helper

    Blog Xing

    Wednesday, October 31, 2012 5:31 AM
  • I have Windows Authentication enabled with Negotiate, NTLM and Negogiate-Kerbores providers.

    For impersonation I tried both ways:

    1) Setting impersonation to true - This way I was able to access the website locally from the machine where IIS server is running. Everything works good but accessing from a remote machine failed with authentication failure right there.

    2) Setting impersonation to false - This way I was able to access the website locally and remotely but when web service tried to make connection to SQL I get that login failed error as posted in my question.

    Wednesday, October 31, 2012 6:33 AM