Error When Trying to Use Npgsql to COPY into a PostgreSQL Database - Mailing list pgsql-general

From Altec103
Subject Error When Trying to Use Npgsql to COPY into a PostgreSQL Database
Date
Msg-id 1403632057022-5808954.post@n5.nabble.com
Whole thread Raw
Responses Re: Error When Trying to Use Npgsql to COPY into a PostgreSQL Database
List 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.


pgsql-general by date:

Previous
From: pgdude
Date:
Subject: Re: Weird error when setting up streaming replication
Next
From: CS_DBA
Date:
Subject: JSON Indexes