views:

191

answers:

1

My SQl Server data base is located in another machine and WCF service and client is on another machine.

While I consume this service ,which in turn access the Sql server to fetch data and return to the client, it gives following error :

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

This error comes when I open the connection.

A: 

I am assuming that you are:

  • Running the WCF service in IIS
  • Using a connection string that spesifies trusted connection
  • Default web.config and IIS settings

In this case it will be the identity of the application pool that will be used to access that database. By default this is a local user so it will not have access to the database.

There are several ways you can fix this:

  • A connection string that specifies user name and password
  • Change the identity of the app pool to a domain user that has access to the database
  • spesify impersonate = true and call the WCF service with a user that has access to the database ...

EDIT 1

The error that you are getting after you turn off IIS anonymous authentication is due to you not sending user information with your request, which means that you get a challenge response back. This requires changes to your WCF configuration. In your case the easiest thing to do is to specify the username and passord in the connection string.

Shiraz Bhaiji
Yes your assumption is true in my case.Please tell me where and how can I specify impersonate = true ??and how to change the identity of the app pool to a domain user that has access to the database
Ashish Ashu
Can SQL EXPRESS support sql server authentication?
adatapost
Yes it supports sql server authentication
Ashish Ashu
One strange thing that I noticed that when I choose "Use Visual Studio Development Server option" in WCF Service application properies page -> Web. I am not getting any error, but when I choose "Use Local IIS Web Server" option in the WCF Service application project and create a virtual directory and intialiae the client with URL like http:/10.12.12.25/MyService/Service1.svc then I will get "Login failed for user ''. The user is not associated with a trusted SQL Server connection" error while opening the connection ..
Ashish Ashu
The same problem is described in the link below:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a42be75e-18f2-4c8c-be28-752c55626ac6
Ashish Ashu
I am giving the user name and password in the connection string but still I am getting this error
Ashish Ashu
What is the error that you are currently getting?
Shiraz Bhaiji