The connection string to my db is set in the Web.config for my project:
<connectionStrings>
<add name="ServiceConnectionString"
connectionString="Data Source=localhost\sqlexpress;Initial
Catalog=Service;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
This is a correct configuration and when I execute stored procedures from the server explorer they return correctly as expected.
My problem stems from when I try to access this db inline with such a call as (AddProduct returns an int):
return new serviceSQLDataContext()
.AddProduct(name, category, price, quantity);
Which fails on this line:
base(global::System.Configuration.ConfigurationManager
.ConnectionStrings["ServiceConnectionString"]
.ConnectionString, mappingSource)
With the first parameter triggering a "Object reference not set to an instance of an object" exception.
How is this possible seeing as in my Web.config I have the correct connection string specified? And is there a solution?