You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
changed the title [-]COPY command: Received unexpected backend message CompletedResponse[/-][+]Better exception on COPY API confusion[/+]on Oct 8, 2017
Activity
roji commentedon 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, notFROM 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.
Better exception on COPY API confusion
[-]COPY command: Received unexpected backend message CompletedResponse[/-][+]Better exception on COPY API confusion[/+]ManeSi commentedon Oct 9, 2017
Thanks for your efforts!