简体   繁体   English

DAAB中的动态连接字符串

[英]Dynamic connection string in DAAB

I am having a situation where i need multiple connection strings to process a request, but i am not able to implement this using the Microsoft enterprise library. 我有一种情况,我需要多个连接字符串来处理请求,但我无法使用Microsoft企业库实现这一点。

somebody please tell me how can i set the connection string dynamically. 有人请告诉我如何动态设置连接字符串。

found similar questions on internet, but none solving my problem, hence posted. 在互联网上发现了类似的问题,但没有解决我的问题,因此发布。

AFAIK, Its not possible to set the connection string dynamically, however you can write a Custom database factory to create a database with dynamic connection string AFAIK,无法动态设置连接字符串,但您可以编写自定义数据库工厂来创建具有动态连接字符串的数据库

    public static class CustomDatabaseFactory
    {
        static readonly DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");

        public static Database CreateDatabase(string connectionString)
        {
            return new GenericDatabase(connectionString, dbProviderFactory);
        }
    }

and instead of calling this 而不是叫这个

Database db = DatabaseFactory.CreateDatabase();

call this method 叫这个方法

Database db = CustomDatabaseFactory.CreateDatabase(connstring);

worked well for me! 对我来说效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM