简体   繁体   中英

Hosting WCF Service that accesses SQL database onto IIS

I have a WCF service that accesses a SQL database to fetch data . I would like to deploy this service onto IIS . However , when i do this , my service is not able to access the database . This is how my service accesses the DB

    SqlConnection thisConnection = new SqlConnection(@"user id=SAIESH\Saiesh Natarajan;" +
                                   "password=;server=SAIESH\\SQLEXPRESS;" +
                                   "Trusted_Connection=yes;" +
                                   "database=master; " +
                                   "connection timeout=30");

I need to know what i should do to be able to access this DB from my WCF service hosted on IIS

Under IIS your service usually will be executed under NETWORK SERVICE account. In your connection string you use trusted_connection=yes . So, you need grant access to NETWORK SERVICE account. But better solution is to change authentication scheme and use USERNAME/PASSWORD to connect to SQL server.
Actually here is similar question WCF Impersonation and SQL trusted connections?

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