views:

48

answers:

1

Hi,

I'm wondering whether it's possible to use built in ASP.NET application services (aspnet_user, aspnet_role etc table) without specifying a connection string in a web.config.

At the moment I store connection strings externally, but I keep finding hard-coded connection strings all over the web.config xml, various providers etc. It's driving me crazy.

Thank you

+2  A: 

You can write your own provider via overriding already existed, built-in class so it will read it's connection string from somewhere else:

public class MyMembershiProvider : SqlMembershiProvider
{
    public override void Initialize(string name, NameValueCollection config)
    {
        config["connectionString"] = "what ever you want";

        base.Initialize(name, config);
    }
}
abatishchev
Hey, thank you for this. This still means that application will look for different configuration files depending whether it's a web.config it's after or app.config. On top of this I have unit tests which seem to be using a conncetion string of their own. LINQ to SQL had connection strings built in some configuration files - I removed those. At the moment my main concern is asp net data providers.
vikp
Spasibo za sovet %)
vikp
@vikp: So you want to minimize the number of connection strings used in the application? You can specify not `connectionString` but `connectionStringName` so it will read it appropriate connection string from Web.config/connectionStrings node. Рад помочь! :)
abatishchev
@vikp: Also you can use special class to hold (manage) your connection string(s). I do so. `public static class Database { public static SqlConnection GetConnection() { } }` which holds your connection string(s) or reads them from Web.config or anywhere else
abatishchev
Sorry for the late reply. Was away. Yes I'd like to minimise the number of places where I store the connection strings. I'm not too keen on web.config or app.config. In my opinion too many things are done for you behind the scenes, which I don't like. I will use a helper class which will read the connection strings from encrypted XML config. Hopefully overhead of reading data from encrypted xml config file won't be too big. Thanks a lot!
vikp