简体   繁体   中英

How do I use a domain account to connect to a database using c#?

I want to create a database using the custom action in the website setup project. but i'm facing a problem doing that in the "website setup project", but when using the regular "setup project", every thing went fine without a problem...

the problem was from the authentication when I want to access the database. It seems that when I use the "setup project" it use my actual username,pass, & the domain. while in the "website setup project" it uses my computer name & for that reason it will not work. since, it doesn't have access to the database.

So, I need a way to tell the website to use my account (I will pass it through the custom action) that include my username,pass, & the domain.

How I can do that in the C#? is there is an API to do that?

Thanks

You can't pass Windows credentials in a connection string. How you would do this is to run your website in IIS(7 and above) and configure your app pool Identity to run under the account you want. See how here: http://technet.microsoft.com/en-us/library/cc771170(WS.10).aspx

This is not how it is done normally though. Normally you would create a sql account in your sql server and then in your connection string you would do something like this:

"Data Source=[ServerName]; Initial Catalog=[DatabaseName]; User Id=[SqlAccount]; Password=[SqlAccountPassword]"

You can then go once step further in sql and configure what access to give to the website account etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM