1

When a user tries to connect to a SQL Server Database through Windows Authentication in my ASP MVC 3 app, with the following connection string:

<add name="btnintranetContext" connectionString="Data Source=BTN-SERVER;Initial Catalog=Intranet;Integrated Security=SSPI;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>

They get the following error:

Cannot open database "Intranet" requested by the login. The login failed.
Login failed for user 'User'. 

I understand what this means, it means that I haven't given that user access to the database, but I want user's to be able to access the database without having to give them all access to it. I've tried specifying a specific Database user in my connection string like so:

<add name="btnintranetContext" connectionString="Data Source=BTN-SERVER;Initial Catalog=Intranet;User Id=mylogin;Password=mypassword;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>

But I get a new error:

Login failed for user 'mylogin'.
The provider did not return a ProviderManifestToken string.

But I know for definite that mylogin has access to the database because when I try to access the database with the windows authentication connection string, it works. But for security reasons, I don't want to give everyone that uses my app access to the database, thats why I tried specifying a user in the connection string.

Additional info from my web.config file:

<authentication mode="Windows" />
<identity impersonate="true" />
<trust level="Full"/>
<authorization>
      <deny users="?" />
      <allow users="*" />
</authorization>

1 Answer 1

1

Set if it's at all possible, and than give the user running the IIS website(usually NETWORK SERVICE be default) access to the database.
If setting impersonate to false is not possible for some reason, you should use SQL authentication instead.

Sign up to request clarification or add additional context in comments.

5 Comments

If I set impersonate to false, the whole app fails when on IIS. I've given Network Service access to the database and it still fails. How would I use SQL authentication? Change the database to use SQL authentication and then pass a SQL user in the connection string replacing my User Id=.. and Password=... with the SQL user?
Yup. That's exactly what you have to do.
Ok I just created a SQL user and passed it's user id and password in the connection string but I still encounter the error: Login failed for user 'sqluser'. The provider did not return a ProviderManifestToken string.
Any chance you are using Entity Framework? If so, are you using DB-first or code-first?
I am using EF yes, and originally I was using code-first before switching to an actual database once my app was completed. But nevermind I managed to fix it, I forgot to restart my server once I switched to SQL and Windows Authentication mode. Thanks for your help, it is appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.