Question

I have an MVC 4 application that uses EntityFramework 4 to connect to a back end database. I'm trying to use Trusted Connection so that as long as the user viewing the web page has rights to the database, I want their Windows account to be used to connect. I searched for solutions and I've put the below in my web.config:

  <system.web>
    <authentication mode="Windows"/>
    <identity impersonate="true"/>
    ...

And I have my connection set up like this:

<add name="MyDbEntities" connectionString="metadata=res://*/MyDbEntities.csdl|res://*/MyDbEntities.ssdl|res://*/MyDbEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MyServer;initial catalog=MyDb;integrated security=True;Trusted_Connection=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I've also played around with impersonation and delegation, but so far, I can't get past the error:

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

All the solutions I've seen recommend modifying IIS on the hosting server, but I will not be able to do that in either our QA or Production environments. So I'm trying to find a solution that uses only code, either something I can do in JavaScript, or in the Controller, or underlying business or data layer.

Thanks in advance for any advice!

Was it helpful?

Solution

Hullo I believe this answer can offer some guidance in a few hours I will probably be able to double check it.

Impersonating user with Entity Framework

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top