CallumVass
CallumVass

Reputation: 11448

Connecting to SQL Server Database with Windows Authentication?

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>

Upvotes: 1

Views: 4287

Answers (1)

Svarog
Svarog

Reputation: 2208

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.

Upvotes: 1

Related Questions