Dynamically creating SQLConnection within WCFService
SqlConnection con = new SqlConnection("Data Source=???.???.???.???;Initial Catalog=DatabaseNa开发者_如何转开发me;Persist Security Info=True; User ID=???; Password=??????;");
How can i dynamically change the datasource within the sqlcollection that is used globally throughtout all the WCFService's methods without adding the parameters to each individual method call?
The server side connection string can be reyrieved from the web.config where it can be saved in the specific settings node ConnectionStrings...
In no case such conn string has to come from the client as the client should not know it. In some cases the client could know the application Name or another specific Key you could use to load proper connection string among several, for example if you imagine to do same operation against different datasources.
At last dont forget that in general is good design to use the service layer to expose certain logic but such logic should be encapsulated in business classes or managers which will call the DAL classes and SqlConnections should be used only inside the DAL classes and all above layers should abstract and no depend to the specific data access logic and implementation details ( aka sql server or oracle or my sql... )
精彩评论