1

I actually deleted the previous connection and the models from my project and added them again. However, now I can't connect to the database again. I verified the connection strings in all the web.config and app.config, but they are the same.

Web.config:

<add name="AuthenticationAppEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

Another web.config:

<add name="AuthenticationAppEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

App.config:

<add name="AuthenticationAppEntities"  
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

I have no idea what could be wrong there. Any help?

When I enable Common Language Runtime Exception, I get this error :

'(db.Table).Local' threw an exception of type 'System.InvalidOperationException'

refresh
  • 1,319
  • 2
  • 20
  • 71
  • 1
    Is there any specific error you are getting ? That would help us get to the root cause faster. – Pradip Oct 27 '15 at 05:35
  • What is that &quot entity doing there? Should that be `'`? Or something messed it up when you pasted it? – Hanlet Escaño Oct 27 '15 at 05:41
  • @Pradip: I am not getting any error message in my error console but in my Output console I have this: 'A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll' and when I watch the db.Table in a query, I have this : '(db.Table).Local' threw an exception of type 'System.InvalidOperationException'. I am blocked with this since 2 days – refresh Oct 27 '15 at 05:47
  • @HanletEscaño: I always have &quot in the connection strings. I am pretty sure it is good, unless if I am missing something here. – refresh Oct 27 '15 at 05:48
  • @tabby, you are getting this when you are trying to open the connection ? or when you build the solution ? – Pradip Oct 27 '15 at 05:49
  • @Pradip: When trying to open the connection. – refresh Oct 27 '15 at 05:51
  • I have added the error I get in the question – refresh Oct 27 '15 at 05:57
  • Why does it says "provider connection string=&quot" in your Conn String ? Could you try changing the &quot to " and try again ? (Escape characters might be required) – Pradip Oct 27 '15 at 06:02
  • @Pradip: you mean change it as above? – refresh Oct 27 '15 at 06:07
  • @Pradip: I changed it as above but I get 'Keyword not supported: 'data source'.' error. – refresh Oct 27 '15 at 06:10
  • Change the Provider Connection String as shown below : – Pradip Oct 27 '15 at 06:13
  • provider connection string='Data Source=MyPC;Initial Catalog=AuthenticationApp;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework'" – Pradip Oct 27 '15 at 06:13
  • catch the first chance exception to find what operation is invalid? – Amit Kumar Ghosh Oct 27 '15 at 06:14
  • @Pradip: Now I am getting this: '(db.Table).Local' threw an exception of type 'System.Threading.ThreadAbortException' or the query keeps on running without any results – refresh Oct 27 '15 at 06:21
  • Lets try one more thing; Try this one and let me know if this works or not. – Pradip Oct 27 '15 at 06:26
  • @Pradip: Just to be sure, I change the connection string in all the web.config where it appears and app.config, right? – refresh Oct 27 '15 at 06:36
  • @Pradip: In my Output console, it says: The 'data source' keyword is not supported. – refresh Oct 27 '15 at 06:39
  • :( I have to check further then. – Pradip Oct 27 '15 at 06:39
  • @Pradip: oh ok. I think I will just delete all the connection and models and add them up again. – refresh Oct 27 '15 at 06:48
  • Fresh start is always is good. Try and let me know if that works out or not. – Pradip Oct 27 '15 at 06:49
  • No luck. I am lost about what to do now. – refresh Oct 27 '15 at 07:00
  • http://stackoverflow.com/questions/33362657/how-to-connect-to-sql-server-express-using-entityframework-solved – Pradip Oct 27 '15 at 08:32

1 Answers1

0

check these links, it may help you.

http://forums.asp.net/t/1749216.aspx?Code+First+Entity+Framework+not+creating+tables+in+the+database

http://www.codeproject.com/Questions/299466/Code-First-Entity-Framework-not-creating-tables-in

How to handle System.InvalidOperationException in entity framework?

I am using connection string something like below

<add name="AuthenticationAppEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=MyPC;Initial Catalog=AuthenticationApp;User ID=xyz;Password=Password@1;MultipleActiveResultSets=True; App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
Community
  • 1
  • 1
Rocky
  • 4,454
  • 14
  • 64
  • 119