New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception on COPY API confusion #1673

Closed
ManeSi opened this Issue Sep 21, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@ManeSi

ManeSi commented Sep 21, 2017

I want to add datas from a csv file into the table tbl_test. This table has no relation, so that it is very easy.
I created my table as following via the SQL-Shell:

CREATE TABLE tbl_test(
id SERIAL PRIMARY KEY NOT NULL,
value INT
);

The Content of my csv file is very Basic:

value
123
234
345
456

No I have a test SUB in Visual Basic .net with the following Content

Public Sub Insert_Into_tbl_Test()
Try
       Using conn = New NpgsqlConnection("Host=" & c_dbHost & ";Username=" & c_user   & ";Password=" & c_password & ";Database=" & c_DBName)
       conn.Open()
            Using writer = conn.BeginTextImport("COPY tbl_test(value) FROM 'C:\temp\test.csv' DELIMITER ',' CSV HEADER;")
            End Using
        End Using

 Catch ex As Exception
   Console.WriteLine("")
   MessageBox.Show(ex.Message)
 End Try
End Sub

Exception message:
Received unexpected backend message CompletedResponse. Please file a bug.

Further technical details

Npgsql version: 3.2.5
PostgreSQL version: 9.6.2
Operating system: Windows 7 Enterprise, Service Pack 1
Programming Tool: Visual Studio Professional 2013 Version 12.0.40629.00 Update 5
Language: Visual Basic

@roji

This comment has been minimized.

Show comment
Hide comment
@roji

roji Sep 22, 2017

Member

If you have your CSV file on the client side (where the Npgsql app is running), then you should be using COPY tbl_test(value) FROM STDIN, not FROM c:\temp\test.csv. The latter is used when the csv file is on the PostgreSQL server. See the documentation.

If you simply want to import a file present on your server, just execute the COPY command as a regular SQL - create a command and execute it with ExecuteNonQuery. Don't use the BeginTextImport API.

Will keep open to fix the error though.

Member

roji commented Sep 22, 2017

If you have your CSV file on the client side (where the Npgsql app is running), then you should be using COPY tbl_test(value) FROM STDIN, not FROM c:\temp\test.csv. The latter is used when the csv file is on the PostgreSQL server. See the documentation.

If you simply want to import a file present on your server, just execute the COPY command as a regular SQL - create a command and execute it with ExecuteNonQuery. Don't use the BeginTextImport API.

Will keep open to fix the error though.

@roji roji self-assigned this Oct 8, 2017

@roji roji closed this in 2a5029e Oct 8, 2017

@roji roji added the 🐞 bug label Oct 8, 2017

@roji roji added this to the 3.2.6 milestone Oct 8, 2017

roji added a commit that referenced this issue Oct 8, 2017

Better exception on COPY API confusion
If a user calls one of the COPY APIs but supplies a server-side file
instead of STDIN, a proper exception is thrown.

Fixes #1673

(cherry picked from commit 2a5029e)

@roji roji changed the title from COPY command: Received unexpected backend message CompletedResponse to Better exception on COPY API confusion Oct 8, 2017

@ManeSi

This comment has been minimized.

Show comment
Hide comment
@ManeSi

ManeSi Oct 9, 2017

Thanks for your efforts!

ManeSi commented Oct 9, 2017

Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment