subsonic 3.0.0.3 多个数据库连接故障转移
我正在使用 MVC 和 Subsonic 3.0.0.3,但我似乎无法确定多个数据库连接的具体点。
通常在普通的.net中我会在web.config文件中包含我的2个字符串 并为我的项目有一个数据库类,在这个数据库类中我会做这样的事情:
try
{
conn.ConnectionString = server1;
conn.Open();
}
catch (MySqlException)
{
conn.ConnectionString = server2;
conn.Open();
}
我试图确定亚音速创建的文件中最好放置这样的文件的一个位置,也许还有一个最新的例子如何实现它。我已经用谷歌搜索过等,但显示的示例适用于较旧的亚音速。
非常感谢
am using MVC and Subsonic 3.0.0.3 but i cant seem to pin down a specific point for multiple database connection.
normally in normal .net i would have my 2 strings in the web.config file
and have a database class for my project, within this db class i would do something like this:
try
{
conn.ConnectionString = server1;
conn.Open();
}
catch (MySqlException)
{
conn.ConnectionString = server2;
conn.Open();
}
I am trying to pin down the one place in subsonic's created files where something like this would be best to place and maybe an up to date example on how to achieve it. I have googled etc but the examples shown are for an older subsonic.
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 Context.tt 的第 35 行,您将看到以下代码:
这是提供程序为您进行设置的位置,因此如果您在 Settings.ttinclude 中第 20 行的 ConnectionStringName 之后添加 BackupConnectionStringName 变量,那么您应该能够检查您的连接是否正常工作,如果不正常则使用后备。例如:
注意,您可能需要进行一些清理,以确保 CreateConnection 不会使连接保持打开状态。
If you look in Context.tt at line 35 you'll see the following code:
This is where the provider is getting setup for you so if you add a BackupConnectionStringName variable in Settings.ttinclude after the ConnectionStringName at line 20 then you should be able to check your connection is working and user your fallback if not. For example:
NB You may need to do some clean up to make sure a connection is not left open by CreateConnection.