C# PostgreSQL复制入和NPGSQL

C# PostgreSQL复制入和NPGSQL,c#,postgresql,bulkinsert,npgsql,C#,Postgresql,Bulkinsert,Npgsql,我正在尝试将数据从stream复制到postgres 我已经准备好文件fl.ext: 1TaboneReturn 2tabtworreturn 3TabthreeReturn 4AbslonyReturn 并编写了测试代码: StreamReader sr = new StreamReader(Console.ReadLine()); NpgsqlCommand cmd = new NpgsqlCommand(string.Format("COPY {0}(id, text) FROM STDI

我正在尝试将数据从stream复制到postgres
我已经准备好文件fl.ext:

1TaboneReturn
2tabtworreturn
3TabthreeReturn
4AbslonyReturn

并编写了测试代码:

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();
但是它在
cin.Start()
上失败,
{“对象引用未设置为对象的实例。”}
并且没有其他详细信息

我做错了什么,伙计们?

只需在
connection.Open()之后移动
NpgsqlCommand
NpgsqlCopyIn
声明即可解决问题。现在可以了