繁体   English   中英

PostgreSQL COPY IN和NPGSQL

[英]PostgreSQL COPY IN and NPGSQL

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

1 Tab返回
2 选项卡返回
3 Tab返回
4 Tab slony 返回

并写了测试代码:

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()上失败, cin.Start()带有{"Object reference not set to an instance of an object."}并且没有其他详细信息。
伙计们,我错了吗?

通过在connection.Open();之后移动NpgsqlCommandNpgsqlCopyIn声明来解决connection.Open(); 现在工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM