Reputation: 2508
I'm trying to copy data from stream to postgres.
I've prepared file fl.ext:
1TaboneReturn
2TabtwoReturn
3TabthreeReturn
4TabslonyReturn
And wrote test code:
StreamReader sr = new StreamReader(Console.ReadLine());
NpgsqlCommand cmd = new NpgsqlCommand(string.Format("COPY {0}(id, text) FROM STDIN;", tableName), connection);
NpgsqlCopyIn cin = new NpgsqlCopyIn(cmd, connection, sr.BaseStream);
connection.Open();
cin.Start();
cin.End();
cin.Close();
But it fails on cin.Start()
with {"Object reference not set to an instance of an object."}
and no additional details.
What I'm doind wrong, guys?
Upvotes: 2
Views: 2352
Reputation: 2508
Solved just by moving NpgsqlCommand
and NpgsqlCopyIn
declarations after connection.Open();
. Now works fine.
Upvotes: 1