Home

Is it possible to update linqpad.config settings on the fly?

We are using LinqPad to script against the Umbraco API. On the whole this is working well for us.

The only thing I don't like is that Umbraco requires an "umbracoDbDSN" connection string in the config file. Now, I can put this in linqpad.config and it does work. However, there are two problems:

Firstly, it's a bit misleading. I can select a connection string in LinqPad, but the one it uses is one I can't see when I'm executing my scripts - this is doubly confusing as some of our scripts access the database as well.

Secondly, it's a pain to swap between different Umbraco instances as I need to keep closing and reopening LinqPad.

Which is to say - is there anything I can do to set config settings on the fly? In an ideal world I would do:

ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString = this.Connection.ConnectionString;

But I get an exception because the configuration is readonly. From googling it looks like I need to open the config file, make the change, save it and then refresh the section. But in LinqPad it's not quite normal (as it uses linqpad.config and not linqpad.exe.config (not sure if I would need to open the config as an XDocument and do it that way). But that feels a bit unwieldy.

I'm just wondering if there is any way I could either tell LinqPad to use a different config file for a particular script and load it on the fly, or if I could somehow modify the settings it uses? Or even if I could pass a commandline option to tell it what config to use, that might be better.

Sorry I know this might be a bit of an obscure question to ask, and from a rummage around reflecting the linqpad source it looks like I probably can't, but I thought I would try my luck anyway! (I guess the ideal is to try to persuade Umbraco to make changes so that the API can work without a config file)

Thanks!

Comments

  • Hi. I've run into a similar scenario and I think this would be a great idea. I manage various API endpoints across several environments (local, dev, prod) for most of my LINQPad scripts. I was considering writing a script that would either swap out versions of the config file with environment settings specified in each version of the config or write a script that changes the config file on the fly before launching LINQPad. Ideally, it would be nice to launch LINQPad via lprun and specify the config file then or swap the file while the app is running like the OP suggested. Thanks!
Sign In or Register to comment.