Asp.net Microsoft数据应用程序块传递数据配置路径
我目前正在为所有与数据库相关的操作使用Microsoft数据应用程序块构建一个应用程序 我在web.config文件中有dataconfiguration的配置设置,如下所示 Web.configAsp.net Microsoft数据应用程序块传递数据配置路径,asp.net,web-applications,web-config,Asp.net,Web Applications,Web Config,我目前正在为所有与数据库相关的操作使用Microsoft数据应用程序块构建一个应用程序 我在web.config文件中有dataconfiguration的配置设置,如下所示 Web.config <storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config"/> <dataTransformer
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config"/>
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
< include Types/>
</data Transformer >
</configuration Section >
我能够成功连接到数据库、查询等
但是,我们在不同的服务器上有不同的配置文件
是否有任何方法可以在代码中传递path属性,并通过加载特定的配置文件而不是在web.config中硬编码来与相应的数据库实例交互???您好您可以使用环境变量并加载良好的配置 1在计算机环境中创建环境变量 环境可以有不同的值:暂存、生产等 2使用此代码获取变量
var variable = System.Environment.GetEnvironmentVariable("YourNameVariable")
if(variable == "STG") //Staging
{
//Load your string connection of staging
}
else if(variable == "PRD") //Production
{
//Load your string connection of production
}
3使用调整后的环境变量,在文件中创建有关配置和加载部分目标的差异部分。Dint完全理解我应该如何做。你能给我指出一个示例代码/例子吗。
var variable = System.Environment.GetEnvironmentVariable("YourNameVariable")
if(variable == "STG") //Staging
{
//Load your string connection of staging
}
else if(variable == "PRD") //Production
{
//Load your string connection of production
}