Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:54:33+00:00 2026-06-09T04:54:33+00:00

If I understand correctly NpgsqlCopyIn with NpgsqlCopySerializer should work something like this: var conn

  • 0

If I understand correctly NpgsqlCopyIn with NpgsqlCopySerializer should work something like this:

var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["PostgreSqlDb"].ConnectionString);
conn.Open();
var tran = conn.BeginTransaction();
var cmd = new NpgsqlCommand("COPY address (id, employee, value) FROM STDIN", conn);
var npgsqlCopySerializer = new NpgsqlCopySerializer(conn);
var npgsqlCopyIn = new NpgsqlCopyIn(cmd, conn, npgsqlCopySerializer.ToStream);

try
{
    npgsqlCopyIn.Start();
    npgsqlCopySerializer.AddInt32(300);
    npgsqlCopySerializer.AddInt32(1);
    npgsqlCopySerializer.AddString("address");
    npgsqlCopySerializer.EndRow();
    npgsqlCopySerializer.Flush();
    npgsqlCopySerializer.AddInt32(301);
    npgsqlCopySerializer.AddInt32(1);
    npgsqlCopySerializer.AddString("another\r\naddress");
    npgsqlCopySerializer.EndRow();
    npgsqlCopySerializer.Flush();
    npgsqlCopyIn.End();

    tran.Commit();
}
//catch (Exception e)
//{
//    tran.Rollback();
//    throw;
//}
finally
{
    conn.Close();
}

Problem is that each time there are not allowed characters in AddString() it throws an ArgumentOutOfRangeException inside that method, otherwise it works.

For example:

npgsqlCopySerializer.AddString("another\r\naddress");

will throw the exception cause it contains a newline which has a special meaning in copy from text format (row separator) and should be escaped.

Anyone know what I can do to make it work? I searched for examples on the internet but I couldn’t find anything.

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:54:34+00:00Added an answer on June 9, 2026 at 4:54 am

    I’m the person who reported the bug, coincidentally only a few days ago.

    Would you mind posting the XML you’re trying to insert? I have tried it with an OSM result:
    http://nominatim.openstreetmap.org/search.php?q=A7&viewbox=3.96%2C52.82%2C7.93%2C51.11&format=xml

    And a rather large web.config file, both work flawlessly. So either I made a copy / paste error while submitting my fix, or the XML you’re trying to insert is different than the XML I tried.

    Also: do you get the exact same error as before (i.e., argument out of range)? The default buffer size is only 8k, which wasn’t enough in my case.

    I don’t know if it makes any difference, but I didn’t use flush at all:

    NpgsqlConnection Conn = new NpgsqlConnection(getPostgresConnString());
    Conn.Open();
    NpgsqlCopyIn copyIn = new NpgsqlCopyIn("COPY table  (col1,col2,col2)   FROM STDIN;", Conn);
    copyIn.Start();
    NpgsqlCopySerializer cs1 = new NpgsqlCopySerializer(pConn2);
    cs1.AddString(System.IO.File.ReadAllText("C:\\test\\Web.config"));
    [...]
    cs1.EndRow();
    cs1.Close();
    copyIn.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does this not work? Do I not understand delegate covariance correctly? public delegate
I'm not sure I understand correctly how QSound.setLoop function should work. I want to
Perhaps I do not understand correctly how MVC Areas work, but this has got
This is just a quick question to understand correctly what happens when you create
If I understand it correctly this means extern void foo(); that the function foo
If I understand this correctly, the program counter points to the address of the
Been trying my best to understand this correctly. What is the difference between an
If I understand correctly, I need to put something in httpd.config to enable mod_rewrite.
I think I may not understand correctly how array_splice is supposed to work. My
I'm new to Java but if I understand correctly, a char is a primitive.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.