Unable to load the connection string name

Today I was concerned by the “Unable to load the connection string name” exception.stefan_scheller_unable_to_load_connection_string

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.

Advertisement
This entry was posted in Dynamics CRM, variouse code. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s