Problem with connectionstring and entityframework

I have a database (mdf file of sql 2008 file), a class library project with an edmx file created using a wizard. Thus, the connection string is also created by the wizard. This project is located on the teamfoundation server.

I can use all objects created by the wizard when encoding.

But when I run the program, and I try to create an entityContainerName, the program crashes and throws this error:

The specified named connection is either not found in the configuration, is not intended for use with EntityClient, or is invalid.

in this line: public TestEntities (): base ("name = TestEntities", "TestEntities")

How can I solve this problem or what am I doing wrong?

+3
source share
3 answers

You need to copy the connection string from the class library configuration file to the configuration file of the application that is actually running.

+5
source

First: delete your model, and then: delete all connection strings in app.config.

Then recreate the model. This should return all the defaults.

+1
source

, EntityFramework , , . . . App.Config. .

public class ExpertDataBase : DbContext
{
    public DbSet<Operator> Operators { get; set; }

    public ExpertDataBase()
        : base(ConnectionFactory.GetCESqlConnection(),true)
    {

    }
}

public static class ConnectionFactory
{
   public static DbConnection GetCESqlConnection()
   {
       DbConnection connection = new SqlCeConnection()
           {
               ConnectionString = @"Data   Source= ",
           };
       return connection;
   }
}

, xml. connectionFactory , - UnityContainer . ,

0

Source: https://habr.com/ru/post/1747016/


All Articles