Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all I have a question,
I am using entity framework with a C# WPF project. I am just doing CRUD with EF for a simple project but I am having issues just starting the project up. At first I was having an error saying “The underlying provider failed on open()”. I ended up getting past that error by looking online and doing what it says. Now I am getting the error “See the InnerException for details. —> System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy“ I am not using Azure. I am just using a .mdf database in SQL on visual studio 2017.
Here is my code that I am using
C#
public class CRUD
    {
        private EntitiesDB entitiesDb = null;


        public Person GetPersonById(int personId)
        {
            return entitiesDb.People.Find(personId);
        }

        public List<Person> GetAllPeopleList()
        {
            return entitiesDb.People.ToList();
        }

        public void AddPerson(Person person)
        {
            if(person != null)
            {
                entitiesDb.People.Add(person);
                entitiesDb.SaveChanges();
            }            
        }

        public void UpdatePerson(Person person)
        {
            Person getPerson = GetPersonById(person.Id);
            if(getPerson != null)
            {
                getPerson.FirstName = person.FirstName;
                getPerson.LastName = person.LastName;
                getPerson.Age = person.Age;
                getPerson.ProgrammingLanguage = person.ProgrammingLanguage;
                getPerson.DateCreated = person.DateCreated;
                entitiesDb.SaveChanges();
            }
        }

        public void RemovePerson(int personId)
        {
            Person removePerson = entitiesDb.People.Find(personId);
            if(removePerson != null)
            {
                entitiesDb.People.Remove(removePerson);
                entitiesDb.SaveChanges();
            }
        }


        public CRUD()
        {
            entitiesDb = new EntitiesDB();
        }
    }
public partial class MainWindow : Window
    {
        //Make Entity Framework object.
        private CRUD framework;
        private Person person;

        public MainWindow()
        {
            InitializeComponent();
            framework = new CRUD();

            PopulateDataGrid();
        }

        private void PopulateDataGrid()
        {
            DataGridPeople.ItemsSource = framework.GetAllPeopleList();
        }


What I have tried:

looking online to get EF to run no luck yet and trying multiple different ideas and topics.
Posted
Updated 14-Nov-18 20:03pm
Comments
TheBigBearNow 15-Nov-18 2:16am    
TRIED LOTS of different techniques to try to get the entity framework to load on the product load()
F-ES Sitecore 15-Nov-18 4:38am    
The problem isn't likely to be your code but your connection string, or your database can't be connected to using the settings in your connection string due to its authentication type, if it accepts remote connections etc. Make sure you can connect to the database using something like SQL Management Studio using similar settings.
#realJSOP 15-Nov-18 7:22am    
Why not just use ADO? Entity Framework is really heavy for simple projects.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900