Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux