We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

C#: ADO.NET Entity Data Model with PostgreSQL crashes

63 Views
Last Modified: 2020-12-09
Hi

I'm using Npgsql with an ADO database first model
When I attempt so save changes  I get this Exception by the changes are saved I think

"This NpgsqlTransaction has completed; it is no longer usable."
Code I've cut it down a bit to make more legible

        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            try
            {
            using (var contex = new gazetteerEntities())
            {
                    var PointOnSurfaces = contex.admin_areas
                        .Where(a => a.fcode == "ADM2" && a.subdivision_code == null).Take(5);
                        //.Where(s => s.subdivision_code == "").Take(5);

                if (PointOnSurfaces == null)
                {
                    Console.WriteLine("Boo Who");
                }
                else
                {
                    foreach (var PointOnSurface in PointOnSurfaces)
                    {
                        var POS_ID = PointOnSurface.id;
                        //var db_lat = PointOnSurface.db_lat;
                        //var db_Long = PointOnSurface.db_long;
                        var db_lat = PointOnSurface.latitude;
                        var db_Long = PointOnSurface.longitude;
                        // Do Stuff
                         // Update this column
                        PointOnSurface.subdivision_code = subdivision_code;


                    }
                    // Exception thrown here
                    contex.SaveChanges();

                }
            Console.ReadLine();
            } // End var contex
            Console.ReadLine();

            }
            catch (Exception e)
            {

                Console.WriteLine("Error: " + e.Message);
            }

        }


Comment
Watch Question
This question hasn't been answered yet.
While you wait, find out how you can maximize your capability with the most trusted tool in IT.
Explore More Ask a Question
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE