views:

153

answers:

1

I created one asp.net mvc application using linq to sql, and in the generated code it created this:

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

Which worked well, However in my next mvc application for some reason it decided instead of looking at the web.config to look at a project resource instead... (and thus when deploying it did not work because the connectionstring was pointing to a dev server.

So to fix this I have edited the new projects datacontext to use the configurationmanager to grab the connectionstring BUT even after adding System.Configuration I cannot access the configuration manager (in my resources I can browse to the System.Configuration.ConfigurationManager and see the ConnectionStrings command, but in the code intellecence does not contain the ConfigurationManager under System.Configuration (but I can see a bunch of other methods, like ConfigurationSettings, for example)

So my questions are:

1\ Why has linq to sql objects decided to use a different method of looking up my connection string in my second project (i.e not use web.config).

2\ What is going on with the ConfigurationManager (why can't I access it?)

A: 

1&2\ The problem is that in my second solution, I have a separate project for the 'Model', and due to it not being in the .web project it does not by default look at the web.config, but in the project resources.

here is a good article how to sort this out: link text

Grayson Mitchell