开关在ASP.NET dynamicaly数据库 [英] Switching dynamicaly database in ASP.NET

查看:97
本文介绍了开关在ASP.NET dynamicaly数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建基于ASP.NET MVC 4多语言的应用程序。
不幸的是,一个数据库适合一个语言。的结构和术语是相同的,而不是被改变的内容。
是否有可能为应用程序根据语言选择更改数据库?

I have to create a multilanguage application based on ASP.NET MVC 4. Unfortunately,a one database suits a one language. The structure and terminology are the same as opposed to the content which is changing. Is there any possibility for the application to change a database according to choice of the language?

推荐答案

不同的连接字符串添加到您的的web.config 的 - 每个支持的语言:

Add different connection strings to your web.config - one for each supported language:

<connectionStrings>
  <clear/>
  <add name="northwind-en" connectionString="server=(local);database=NorthwindEnglish;Integrated Security=SSPI"/>
  <add name="northwind-fr" connectionString="server=(local);database=NorthwindFrench;Integrated Security=SSPI"/>
</connectionStrings>

然后,根据所需的语言,或默认选择其一连接字符串如果对于选择的语言没有具体的数据库:

Then select connection string depending on required language, or default one if there is no specific database for selected language:

var availableLocales = ConfigurationManager.ConnectionStrings
                                .Cast<ConnectionStringSettings>()
                                .Select(cs => cs.Name)
                                .Select(n => n.Substring(n.IndexOf('-') + 1));

这篇关于开关在ASP.NET dynamicaly数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆