Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: No connection string named ....could be found in the application config file. #11

Open
khuzemakanore opened this issue Nov 2, 2017 · 4 comments

Comments

@khuzemakanore
Copy link

khuzemakanore commented Nov 2, 2017

I created a new class project .Net Framework 4.5.2

I have generated the POCO class using EntityFramework Reverse POCO Code First Generator.

And created a app.config file and specified connection as mentioned below : -

    <connectionStrings>
        <add name="DBConnection" connectionString="Server=.;Database=Zza;Trusted_Connection=true" ProviderName="System.Data.SqlClient"/>
    </connectionStrings>

But MetaDataGenerator not accepting the above connection string and gives error.

"No connection string named DBConnection could be found in the application config file."

The DBContext.cs has following constructor

public DBContext() : base("Name=DBConnection") { }

Please can you guide ...

@marcelgood
Copy link
Collaborator

There are a couple of things you can do. You can add the connection string to MetadataGenerator.exe.config. The MetadataGenerator won't find your app's app.config. You can leave out the connection name and string and ensure that SQL Express is installed on your machine. EF by default tries to connect to SQL Express if no connection string is supplied, or you can set the DB Initializer to null in your DBContext, so EF doesn't try to connect to a DB at all during the metadata generation.

@khuzemakanore
Copy link
Author

khuzemakanore commented Nov 2, 2017

Thank you very much. It worked with providing connectionString in MetadataGenerator.exe.config.

Can we put this thing in readme.

BreezeJs is amazing

I hope you guys give some love to AureliaJS :)

@AbakumovAlexandr
Copy link

AbakumovAlexandr commented Feb 19, 2018

I think this certainly should be added to docs.
moreover, that page says in the beginning:

  • Start from an existing database, derive a conceptual model from the database schema, and generate entity classes from that conceptual model.

but the rest of the page describes Code First approach and doesn't give any information about the DB First one. DB First approach seems to be missed from the docs entirely.
However, when you try to pass an Entity Model created with the DB First approach to the Metadata Generator, the exception described by OP will be thrown.

@AbakumovAlexandr
Copy link

AbakumovAlexandr commented Feb 19, 2018

@marcelgood: Could you please expand on your suggestion:

or you can set the DB Initializer to null in your DBContext, so EF doesn't try to connect to a DB at all during the metadata generation.

I added the following method to my DBContext:

    public partial class Entities : DbContext
    {
        static Entities()
        {
            Database.SetInitializer((IDatabaseInitializer<Entities>)null);
        }

Is this what you intended as the fix?

It still throws:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants