0
votes

I created a WCF Data Service (v5.5, anonymous) that uses Entity Framework (v4.4) to access a database. I created Service Operations to fetch the data.
In my config file, there is no user id and password set in the Connection String . I created a partial class of the Context, where I put a constructor that injects the necessary id and password into the connection string. As my service operations uses this context (initialized by that contructor), the database is accessed by the given user.
Fetching works fine, but when I try to insert, I get an exception:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
Clearly, somehow the context was recreated or the connection string reused, as the user and password is not set.
What should I modify to force the insert context to use the modified connection string?

1

1 Answers

1
votes

You can override the CreateDataSource method on the service class that derives from DataService<>, then return the context created using the appropriate constructor. That should take care of this issue.

By default, WCF Data services calls the default constructor on the context.

Thanks Pratik