The specified named connection is either not found in the configuration, not intended to be used with the EntityClient p

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
flycast
Posts: 19
Joined: Mon 04 Feb 2019 19:39

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient p

Post by flycast » Wed 08 Sep 2021 17:19

Using Entity Developer in a class library .NET version 4.7.2 project. When I add an Entity Developer it adds fine, connects to the database ok and builds the code. The connection string is added to the app.config file. All the details of the connection string check out. When I run the class library and use Entity Framework stuff it the following exception happens:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
My EF code:

Code: Select all

                using (var context = new SWPDMEngVaultEntitiesTwo())
                {
                    var docNumber = (from p in context.Projects
                                     join dip in context.DocumentsInProjects on p.ProjectID equals dip.ProjectID
                                     join d in context.Documents on dip.DocumentID equals d.DocumentID
                                     where p.Path == path
                                            && d.Filename == fileName
                                            && dip.Deleted == 0
                                     select d.DocumentID).FirstOrDefault();

                    if (docNumber == 0)
                    {
                        throw new Exception("Part ID was not found.");
                    }
                    else
                    {
                        return docNumber.ToString();
                    }
                }
I have confirmed that the connection string in app.config is correct. I have tried to create a completely new Entity Developer item and the new one acts the same. I suspect that this is because the project is a class library??? What should I check?

**EDIT**
It seems that Entity Developer stores the connection string in the app.config file by default. The app.config file is not used in a class library. How to get the connection string in a class library?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: The specified named connection is either not found in the configuration, not intended to be used with the EntityClie

Post by Shalex » Thu 09 Sep 2021 11:32

flycast wrote: Wed 08 Sep 2021 17:19The app.config file is not used in a class library.
You can copy the generated connection string from app.config of your class library to app.config of the project that references the class library.
flycast wrote: Wed 08 Sep 2021 17:19How to get the connection string in a class library?
Please open Model Settings and clear the selection of the "Use the following connection string from App.Config" option to pass the connection string to the context constructor directly in the code.


Post Reply