Can I Add ConnectionStrings to the ConnectionStringCollection at Runtime?

前端 未结 8 1453
心在旅途
心在旅途 2020-12-15 18:38

Is there a way where I can add a connection string to the ConnectionStringCollection returned by the ConfigurationManager at runtime in an Asp.Net application?

I hav

8条回答
  •  不知归路
    2020-12-15 19:04

    Haven't tried it yet, but perhaps you can alter the value of an existing connection string at runtime? For example, instead of:

    ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings(params));
    

    Maybe you could do something like:

    ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString = "something";
    

    If so, you could specify the connection string "variables" in config, but set them to false or empty connection strings:

    
    

提交回复
热议问题