实体框架中的连接字符串
我使用实体框架在ASP.NET中引用了2个数据库。
在我的 web.config
文件中,我可以看到2个数据库的连接字符串:
<connectionStrings>
<add name="RContext"
connectionString="metadata=res://*/Models.RModel.csdl|res://*/Models.RModel.ssdl|res://*/Models.RModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost\SQLEXPRESS;initial catalog=RStreamline;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
<add name="CEntities"
connectionString="metadata=res://*/Models.CModel.csdl|res://*/Models.CModel.ssdl|res://*/Models.CModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost\SQLEXPRESS;initial catalog=RStreamline;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
我可以以某种方式实现替代连接字符串,该连接字符串在其中数据源引用prod Server以供发布?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常用。
在您的项目中,您将拥有:
例如在您的web.release.config transform中,您会拥有类似的东西:
您会注意到
xdt:transform =“ setAttributes” xdt:loacator:locator =“ Match(name)”
位,其中说,在主web.config中,通过名称找到连接串,然后用此处定义的属性替换其属性。当您发布应用程序时,这将自动发生。
This is typically handled with web.config transforms.
In your project you would have:
For example in your web.Release.config transform you would have something like this:
You'll notice the
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"
bit, which says, in the main web.config find the connectionString by name and replace its attributes with the ones defined here.This will automatically happen when you publish the application.