开发者

Dynamically creating SQLConnection within WCFService

开发者 https://www.devze.com 2023-04-12 12:14 出处:网络
SqlConnection con = new SqlConnection(\"Data Source=???.???.???.???;Initial Catalog=DatabaseNa开发者_如何转开发me;Persist Security Info=True; User ID=???; Password=??????;\");

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... )

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号