3

I'm attempting to create a copy of a database schema, and then use it in the application temporarily for testing purposes so I don't alter live data. However, no matter what I do, it always gives me this error:

An exception of type 'System.ArgumentException' occurred in System.Data.Entity.dll but was not handled in user code

Additional information: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

I have tried making my connection strings look like the following:

<add name="EntitiesConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\vipertest.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

<add name="EntitiesConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\vipertest.mdf;Integrated Security=SSPI;User Instance=True" providerName="System.Data.SqlClient"/>

I've tried with an mdf file, and without.

I've done this in both Web.Config and app.config, but I always get the same error.

  • Your connection string doesn't in fact look like an Entity Framework connection string. Posted an answer that might help explain. – Ayo I Apr 13 '16 at 19:06

1 Answers1

2

Entity framework connection strings don't typically look like either of the strings you're showing. Your connection string looks like a plain sql server connection string.

An EF connection string typically contains EF metadata. Here is an example from one of my EF connection strings:

So you're connection string may look somewhat different, but it should contain entity metadata references, etc.

I would start with the actual connection string being used in production (if you can get it), even sanitized, and then modify it accordingly.

This MSDN article on EF connection strings might help.

Ayo I
  • 7,722
  • 5
  • 30
  • 40
  • Thank you for the response, I didn't think about that - I will go try it out :) – Brandon Hyder Apr 13 '16 at 19:13
  • It worked! I've marked your response as the answer - thank you! What I did was take the connection string with meta data in it from production like you said, and then just replaced the connection string section with the first connection string I have as an example in the question. – Brandon Hyder Apr 13 '16 at 19:18
  • Glad that helped you. – Ayo I Apr 13 '16 at 19:41
  • I seem to be getting an error that says "The underlying provider failed on Open." when I'm attempting to actually access the data. – Brandon Hyder Apr 13 '16 at 19:53
  • Hmm, it might be easier to post this as a different question with your new connection strings, any relevant code, etc. and I can take a look. – Ayo I Apr 13 '16 at 21:55
  • Yeah, I agree - I posted one recently with the details; thank you for taking the time! Here is the link: http://stackoverflow.com/questions/36610948/localdb-error-when-accessing-data-the-underlying-provider-failed-on-open – Brandon Hyder Apr 14 '16 at 01:07