1

A brief background: I am creating a web application and need this to pull data from SCOM 2012 DB(SQL Server 2012), this DB is set to Windows Authentication only, this will not be changed in the foreseeable future as the company are unwilling to do this.

Problem: I have looked around extensively on this issue however I am unable to find a solution. I need to create a connection to the DB running as a specific windows user to pull back to data. To make this clear I do not want to impersonate the end user using the web app. I have the credentials for the account I would like to use for this however I need some assistance in doing this if its possible!

1
  • do you have an example? is this in the connection string? Thanks Tom Commented Jun 27, 2013 at 1:53

3 Answers 3

4

The connection has to be made in the context of the windows user that has login access to the database. You cannot do it through the connection string.

You can do this by setting the app pool identity to this specific user (which is fairly standard practice). Or you can have a method that impersonates the user for the call to the database, though that is a little more involved. See How do you do Impersonation in .NET? for examples.

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

4 Comments

@RattyLaa note, that although you mentioned that you do not want to impersonate the end user using the web app, this answer gives you a valid approach, since you'll be impersonating the user that has access to the SQL server.
@Aron I think that you misread the answer/comment. Neither is suggesting impersonating the end user using the web app.
I have tried modifying the applicationHost file to change the username and password for the app pool locally on my machine for IIS express however when running the app in VS its still trying to make the connection to the DB as my local user account, any ideas?
IIS Express runs under the logged in user account -- you might try logging in as that user and running VS, or since I hope you are debugging in a test environment, you might see if you can get your credentials added to the test DB.
1

If the company is inside a domain, and the user running the iis has permisions on the SQL Server, all you have to do is use windows authentication and that's it.

Check out: http://msdn.microsoft.com/en-us/library/2xzyzb0f(v=vs.100).aspx

1 Comment

This sounds like it may be the easiest option
1

You could set up a web service between your web app and your database, and run your web service under the account that has access to the database by putting

<system.web>
    <identity impersonate="true" userName="domain\login" password="pwd" />
    ...
</system.web>

into the web service's web.config.

Then your web app could call the web service to get/save the data.

I know this works because I an working with an app that does this. Perhaps you could just put the impersonate into your web app's config file and access the database directly, but I don't have any experience with that.

2 Comments

Thanks for all the answers guys, changing the App Pool may be the easiest way to go about this if i cannot get anything else to work.
I did try and add the <identity> and set the impersonation level to true but no joy thanks for the suggestion

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.