How does the ContextManager access the web.config

How does the ContextManager access the web.config

Old forum URL:

WillGo posted on Wednesday, April 06, 2011

I am new to this forum and fairly new to CSLA, have been working with it for a couple of months.  We have a ASP.NET application writen in c# using CSLA.NET 3.6, linq to sql and Sql Server 2008 as the back-end. The database name is CIMS and is on a separate database server.  We have a number of separate projects in the application, including a project that includes the generated L2S code "DalLinq" and a number of projects that contain the CSLA business layer.  A typical data access fetch looks like this:





using (var mgr = ContextManager<Cis.Cims.DalLinq.CimsDataContext>.GetManager(Database



  // perform some linq query


Database.Cims returns "Cims", the name of the database.

I've recently added a new gridview using a linqdatasource to populate.  The ContextTypeName for the LinqDataSource is CimsDataContext, the main DataContext for the application. This grid works fine locally.  However after publishing to our test server and acessing this page remotely, I am met with:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

Other parts of the application not using the linqdatasource seem to work fine, both on my machine and on the test server.  In stepping through the code I can see where the LinqDataSource is calling the CimsDataContext constructor which is retrieving the connectionstring from the project's app.config.  This connection string is pointed to "localhost", which would explain why it works on my machine, but not on our test web server. 

All of the connections strings are stored in the web.config, not the the "DalLinq" app.config.  There are no references to the database server in the app.config, only the web.config.  How is it that the ContextManager accesses the web.config to get the proper connection string? 

What would recommend to fix this problem?  I don't want to spread connection strings around to different config files, so putting the correct connection string in the app.config is not a solution.  Thanks in advance,



RockfordLhotka replied on Wednesday, April 06, 2011

ContextManager gets the connection string by using the ConfigurationManager object's connection string collection. The ConfigurationManager type is in the System.Configuration namespace.

In short, it uses the standard .NET way to get elements from the <connectionStrings> element of the config file.

WillGo replied on Wednesday, April 06, 2011

Wow.  I assumed that the ConfigurationManager would not access the web.config from a library project.  Thanks

Copyright (c) Marimer LLC