Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

Why do I get an exception when doing a bulk insert into a PostgreSQL DB in my .Net application?

I have a VB .Net application which talks to a backend PostgreSQL database.
I'm using NpgSQL to run queries against that database.

In order to get better performance for bulk inserts into the database, I'm using the PostgreSQLCopyHelper (http://bytefish.de/blog/postgresql_bulk_insert/)

I have used it successfully in other C#/.Net applications.
I have however run into issues when I integrated into my current VB.Net application.

This roughly what my code currently looks like:

 
  Dim copyHelper As PostgreSQLCopyHelper(Of FooClass)
    Dim entities As IEnumerable(Of FooClass)
    
     Dim connection As NpgsqlConnection
    
    connection = New NpgsqlConnection(connectionString)
    connection.Open()

    copyHelper.SaveAll(connection, entities)

Open in new window

   

I get the following exception when I attempt to do a SaveAll():

HResult -> -2146233079
Message      -> "Can't close writer, a row is still in progress, end it first"      

With the following stacktrace:

   at Npgsql.NpgsqlBinaryImporter.Close()
   at Npgsql.NpgsqlBinaryImporter.Dispose()
   at PostgreSQLCopyHelper.PostgreSQLCopyHelper`1.SaveAll(NpgsqlConnection connection, IEnumerable`1 entities)


How do I go about debugging this?


Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial