Today I was concerned by the “Unable to load the connection string name” exception.
Simplified my setup looks like in the picture. I am running a ms unit test project with a service reference for the WCF service and the service references a class library to come a long with the business tasks.
Within the class library I use the ms crm xrm framework to get a typed layer of your crm business objects.
The xrm data context is build up like that:
var context = new Xrm.mynameDataContext("MyConnectionString");
By running the unit test I got all the time the exception “Unable to load the connection string myConnectionString”. I did add the connection string to my Class Library app.Config and my client app.config like that:
<configuration>
...
<connectionStrings>
<add name="MyConnectionString" connectionString="Authentication Type=AD; Server=http://myserver/myorganisation; User ID=mydomain\myaccount; Password=*****"/>
</connectionStrings>
...
</configuration>
The DataContext tries to retrieve the connection string like this:
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
So the ConnectionStrings Collection did never contain the connection string.
With a second look on the architecture finally I got the clue: The point is that my entry point on server side for the library execution is obviously not the client.
solution is:
Add your connection string to your WCF Service web.config or app.config
The calling client does not need any connection strings, sometimes logical things let us stumble especially if we got many layers in real life projects.