views:

115

answers:

1

I have asked this question http://stackoverflow.com/questions/1900415/what-is-the-best-way-to-dynamic-load-connection-strings

But maybe it's better to ask the question a little different.

I have a CRM solution where I have different SQL databases for each company, but I would like to try to only have one IIS site, since the site is always equal except for the SqlConnectionString in the Web.config file. I use LinqToSql and generates the classes automatic using the tools in VS2008. This means that I have the DataClasses wich is automatic generated. I found that this class reads the connection string from the web.config in this line:

public DataClassesDataContext() : 
 base(global::System.Configuration.ConfigurationManager
             .ConnectionStrings["TheConnectionString"].ConnectionString,
             mappingSource)
{
 OnCreated();
}

The users all logs into the same IIS site wich I want to auhenticate against AD and then redirect them to the CRM site, when I do I would like to dynamic get the right ConnectionString and make the Linq class use that.

Am I on the right track to make this happen? And if so, how do I achieve to load the connectionstring dynamic for the linq classes, the file wich the code above is found is autogenereated and is deleted everytime I compile.

Any ideas?

+2  A: 

You can do that if in linqmetal desinger click on it and then in the property window on sql connection you set to blank so the autogenerate dont owerwrite you code. Then you create partial class for you datacontex and then you create this contructor by your self example:

 public partial class DataClassesDataContext
    {
        public DataClassesDataContext()
            : base(StaticMethodThatYouDoLogicForConnStringDecision(), mappingSource)
        {

        }
    }
Florim Maxhuni
thank you. That is working. Do you know how I can read from a session variable where you put the StaticMethodThatYouDoLogicForConnStringDecision?
espenk
Nevermind. I got it
espenk