NpgsqlCopySerializer blows up if no rows are saved - Mailing list pgsql-general

From AK
Subject NpgsqlCopySerializer blows up if no rows are saved
Date
Msg-id 1386019730185-5781300.post@n5.nabble.com
Whole thread Raw
Responses Re: NpgsqlCopySerializer blows up if no rows are saved  ("Francisco Figueiredo Jr." <francisco@npgsql.org>)
List pgsql-general
I am not sure if this is the correct place to post my question to. If this is
a wrong list, can you tell me the right one.

I am bulk loading rows using the following code:

const string connString =
"myConnString";
using(var conn = new NpgsqlConnection(connString))
{
conn.Open();
var command = conn.CreateCommand();
var copyStr = string.Format("COPY staging.test(col1,col2) FROM STDIN");
command.CommandText = copyStr;
command.CommandType = CommandType.Text;
var serializer = new NpgsqlCopySerializer(conn);
var copyIn = new NpgsqlCopyIn(command, conn, serializer.ToStream);
copyIn.Start();
foreach (var row in incomingRows)
{
//feed the values here
}
copyIn.End();
serializer.Flush();
serializer.Close();
command.Dispose();
}
If incomingRows has one or more items, this works. However, if no rows are
saved, serializer.Close() blows up:

System.NullReferenceException : Object reference not set to an instance of
an object.
at Npgsql.NpgsqlCopySerializer.Close()

What am I doing wrong?





--
View this message in context:
http://postgresql.1045698.n5.nabble.com/NpgsqlCopySerializer-blows-up-if-no-rows-are-saved-tp5781300.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: Re: Help ! FAILOVER with Slony-I.
Next
From: bricklen
Date:
Subject: Mismatched pg_class.reltuples between table and primary key