【问题标题】:PostgreSQL COPY IN and NPGSQLPostgreSQL 复制输入和 NPGSQL
【发布时间】:2015-06-11 13:27:32
【问题描述】:

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

1制表符一个返回
2Tab两个返回
3Tab三个返回
4制表符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(){"Object reference not set to an instance of an object."} 上失败,并且没有其他详细信息。
伙计们,我做错了什么?

【问题讨论】:

    标签: c# postgresql bulkinsert npgsql


    【解决方案1】:

    只需将NpgsqlCommandNpgsqlCopyIn 声明移到connection.Open(); 之后即可解决。现在工作正常。

    【讨论】:

      猜你喜欢
      • 2018-12-10
      • 2022-11-11
      • 2012-04-30
      • 2016-07-08
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2016-08-21
      相关资源
      最近更新 更多