亚音速3.0.0.3多个数据库连接故障转移

编程入门 行业动态 更新时间:2024-10-19 17:43:21
本文介绍了亚音速3.0.0.3多个数据库连接故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用MVC和亚音速3.0.0.3,但我似乎无法牵制多个数据库连接的特定点。

am using MVC and Subsonic 3.0.0.3 but i cant seem to pin down a specific point for multiple database connection.

通常在正常.NET我有我的web.config文件中的2个字符串并且有一个数据库类为我的项目,该DB类中我会做这样的事情:

normally in normal 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(); }

我想牵制在亚音速的创建文件的一个地方,这样的事情将是最好的地方,也许一个最新的例子就如何实现这一目标。我用Google搜索等,但显示的例子是一个较旧的亚音速。

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.

非常感谢

推荐答案

如果您在Context.tt在第35行看看,你会看到下面的code:

If you look in Context.tt at line 35 you'll see the following code:

public <#=DatabaseName#>DB() { DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>"); Init(); }

这是那里的供应商越来越为你设置,所以如果你在Settings.ttinclude在第20行中的connectionStringName后添加BackupConnectionStringName变量,那么你应该能够检查你的连接工作和用户的后备如果不是。例如:

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:

public <#=DatabaseName#>DB() { DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>"); Init(); try { DataProvider.CreateConnection(); } catch(SqlException) { DataProvider = ProviderFactory.GetProvider("<#=BackupConnectionStringName#>"); Init(); } }

NB您可能需要做一些清理,以确保连接不剩通过创建连接开放。

NB You may need to do some clean up to make sure a connection is not left open by CreateConnection.

更多推荐

亚音速3.0.0.3多个数据库连接故障转移

本文发布于:2023-10-23 05:43:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:亚音速   多个   数据库连接   故障

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!