1

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

Saiesh
  • 641
  • 2
  • 7
  • 23
  • Where is the database in relation to the web server? Are there firewalls possibly in the way? is your sqlexpress setup for remote connections? – BugFinder Jul 06 '12 at 07:30
  • 3
    Well, for one - **either** you specify a UserId/password, **or** you define a `Trusted_Connection` (or `Integrated Security`) to use the current credentials - but you **should not** define both in the same connection string – marc_s Jul 06 '12 at 07:31
  • I tried running the service locally using it's localhost URL assigned by default by VS10 and not from IIS and it works fine only when both the UserId/password AND trusted_connection are included . I realize something is wrong but am not able to determine what . – Saiesh Jul 06 '12 at 08:09

1 Answers1

1

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?

Community
  • 1
  • 1
paramosh
  • 2,258
  • 1
  • 15
  • 23