1

I need to consume some .net code from classic ASP, hence I am using com interop.

This works well apart from EF6 and its connection strings. When I try and call the method that uses EF from classic ASP I get

No connection string named 'Entities' could be found in the application config file. 

So I thought I would code the connection string into the context with the following:

    using (Entities context = new Entities())
    {

        context.Database.Connection.ConnectionString = @"metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=server;initial catalog=database;persist security info=True;user id=sa;password=PasswordRemoved;MultipleActiveResultSets=True;App=EntityFramework'";

However, at runtime from my .net test harness, when that method is called, we once again get:

No connection string named 'Entities' could be found in the application config file.

I made sure I specified that I would set the connection string in my code in the entity creation wizard, and subsequently the connection string isn't in my app.config file.

What is stopping EF6.1 from accepting my connection string in code rather than from the config file? Important to note I have scoured SO for solutions and none of them have stuck.

MagicalArmchair
  • 911
  • 1
  • 12
  • 26
  • Where do you call the Entity-framework code from? If it was for example from a console app you need to add the connection string to the console app config file, and same for the test app. – Omar.Alani Nov 16 '14 at 01:43
  • The question is to avoid the use of config files and to specify the connection string in code. I have tried in the com deployment to put the connection string in the machine.config, web.config, specify the application path in Component Services and put an app.config and app.manifest in there, none of these have worked, however I did not add those details above as they are not relevant to the atomic question. – MagicalArmchair Nov 16 '14 at 01:46
  • This may help you http://stackoverflow.com/questions/6003085/how-do-i-programmatically-set-the-connection-string-for-entity-framework-code-fi – Omar.Alani Nov 16 '14 at 02:01
  • I had already visited that link, unfortunately not. The earlier answer assumes you can specify the connection string in the constructor (which it would appear you can no longer do), and the latter answer from Sept I have tried above and appears to not work in EF6.1. – MagicalArmchair Nov 16 '14 at 16:18

0 Answers0