Question

I'm loosely following an excellent series of blog posts by Kazi Manzur Rashid as a learning exercise for learning how to implement some new (for me at least) design patterns, but I'm getting trouble from the start.

I've basically copied his code for the Database, RepositoryBase and RepositoryBaseTests classes, but when I try to run the tests, I get an error message saying

Unable to create instance of class Booking.Infrastructure.EntityFramework.Repositories.Tests.RepositoryBaseTests. Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0..

Through the debugger I have verified that the exception is thrown on the constructor for the Database class, which looks like this:

public Database(
    IConfigurationManager configurationManager, 
    string connectionstringName)
: base(
    GetConnectionString(configurationManager, connectionstringName), 
    "BookingEntities")
{ // Nothing happens here }

The error is thrown when calling the base constructor, and if I'd hard-code the values that I'm currently sending in, it would look like this:

: base("Dummy connStr", "BookingEntities")

Why doesn't this work?

Was it helpful?

Solution

"Dummy connStr" is not a valid EF connection string.

A valid EF connection string looks like:

connectionString="metadata=res://*/Data.Model.csdl|res://*/Data.Model.ssdl|res://*/Data.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SERVERNAME\SQLDEV2008;Initial Catalog=DBName;Integrated Security=True;MultipleActiveResultSets=True""
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top