Error When Trying to Use Npgsql to COPY into a PostgreSQL Database

From: Altec103 <goldenbabbler(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Error When Trying to Use Npgsql to COPY into a PostgreSQL Database
Date: 2014-06-24 17:47:37
Message-ID: 1403632057022-5808954.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am currently in the process of using an ODBC Connection and a Npgsql
Connection to transfer a database from a Sybase/Advantage platform to a
PostgreSQL platform using C# and the .NET framework.

Below is the code I have come up with to transfer the data itself...

NpgsqlCommand copyCommand = new NpgsqlCommand("COPY \"2009info.adt\" FROM
STDIN", connectionTest);

string query = "SELECT * FROM \"2009info.adt\"";
OdbcCommand test = new OdbcCommand(query, myConnection);
string dataEntry = "";

NpgsqlCopyIn copy = new NpgsqlCopyIn(copyCommand,
connectionTest);

copy.Start();

OdbcDataReader reader = test.ExecuteReader();

int rowCount = reader.FieldCount;

while (reader.Read())
{

for (int i = 0; i < rowCount; i++)
{
dataEntry = dataEntry + reader[i].ToString() + "|";
}

dataEntry = dataEntry.Trim().Substring(0, dataEntry.Length -
1);
dataEntry = dataEntry.Replace("\r",
string.Empty).Replace("\n", string.Empty);

var raw = Encoding.UTF8.GetBytes(dataEntry);
copy.CopyStream.Write(raw, 0, raw.Length);

dataEntry = "";
}

copy.End();

However, nothing happens when this code compiles. And when I look at the log
files I get the following errors.

2014-06-24 13:22:58 EDT CONTEXT: COPY 2009info.adt, line 1
2014-06-24 13:22:58 EDT STATEMENT: COPY "2009info.adt" FROM STDIN
2014-06-24 13:22:58 EDT ERROR: unexpected EOF on client connection with an
open transaction
2014-06-24 13:22:58 EDT CONTEXT: COPY 2009info.adt, line 1
2014-06-24 13:22:58 EDT STATEMENT: COPY "2009info.adt" FROM STDIN
2014-06-24 13:22:58 EDT LOG: could not send data to client: No connection
could be made because the target machine actively refused it.

Anyone have any ideas why this is happening?

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Error-When-Trying-to-Use-Npgsql-to-COPY-into-a-PostgreSQL-Database-tp5808954.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Heikki Linnakangas 2014-06-24 17:49:05 Re: Extended Prefetching using Asynchronous IO - proposal and patch
Previous Message pgdude 2014-06-24 16:04:45 Re: Weird error when setting up streaming replication