如何改变对飞亚音速3的连接字符串? [英] How do you change SubSonic 3's connection string on the fly?

查看:342
本文介绍了如何改变对飞亚音速3的连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想换一些查询在SharedDbConnectionScope和不同的连接字符串下执行。我如何才能做到这一点动态添加提供程序/连接字符串?

I want to wrap some queries in a SharedDbConnectionScope and execute them under a different connection string. How do I add a provider/connection string dynamically in order to do this?

感谢

推荐答案

无论是的ActiveRecord \Context.tt LinqTemplates\Context.tt ,你会用来生成类包含构造函数:

Both the ActiveRecord\Context.tt and the LinqTemplates\Context.tt that you would use to generate your classes contain constructors:

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

    public <#=DatabaseName#>DB(string connectionString, string providerName)
    {
        DataProvider = ProviderFactory.GetProvider(connectionString,providerName);
        Init();
    }



所以,你可以在你的连接字符串传递给这些构造,像之一:

So you can pass your connection string to one of these constructors, like:

// point to a certain connection string in the app.config
var db = new MySample("SomeConnectionStringName");

// Use a specific connection string, not the app.config
var db = new MySampleDB(@"server=.\SQL2008;database=Sample;integrated security=true;", "System.Data.SqlClient");

这篇关于如何改变对飞亚音速3的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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