tags:

views:

13

answers:

1

I have multiple SQL Server databases with the same schema. I would like to use one WCF data service (Rest service) to access the different databases.

How can I accomplish this so the client can pass in the correct database name or connection string?

+1  A: 

You could define some query string parameters, something like:

http://YourServer/YourService/SomeUrl?database=MyDatabase1

and then in your server-side code, use that database=MyDatabase1 to dynamically build the connection string, that you then use to open a connection to the database. Shouldn't be too hard, I think!

marc_s
Yes, but the security is a big issue with passing the variable in vissible in the URL. I'm using entityset on the serverside to autmatically create the service, not sure how to override the connectionstring there.
espenk
@espenk: the EF's ObjectContext has a constructor that allows you to specify a entity context name - see http://msdn.microsoft.com/en-us/library/bb739017%28v=VS.100%29.aspx - that's an arbitrary name, too - it doesn't have to match the database at all - so even if you pass a clear text string in the URL, that doesn't have to be the actual database name....
marc_s
Hmm. Ok, but do you mean that I need to make a new partial class in the serverside WCF service? The service I've made is just auto generated, and only contains this method: public static void InitializeService(DataServiceConfiguration config)Could you please enlight me some more, thank you
espenk