|
|
|
npgsql и NpgsqlCopyIn() качаю csv в таблицу ... закачивается, но не все данные(((
|
|||
|---|---|---|---|
|
#18+
private void button1_Click(object sender, EventArgs e) { Encoding inEncoding = System.Text.Encoding.Default; Encoding serverEncoding = System.Text.Encoding.UTF8; String separator = "\";//знак слеша string outputPathname = Environment.CurrentDirectory + separator + "file.csv"; FileStream inStream; string targetTableName = "tbl_grd"; var conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;UserId=postgres;Password=321123;Database=exotic;"); inStream = new FileStream(outputPathname, FileMode.Open); using (var connection = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=321123;Database=exotic;")) { connection.Open(); using (var command = new NpgsqlCommand("COPY " + targetTableName + " FROM STDIN DELIMITER ';' ", connection)) { var copy = new NpgsqlCopyIn(command, connection); try { copy.Start(); Stream copyInStream = copy.CopyStream; byte[] buf = new byte[(int)inStream.Length]; int offset = 0; int remaining = buf.Length; while (remaining > 0) // вроде и проверяю немного чтоб все закачалось { int read = inStream.Read(buf, offset, remaining); if (read <= 0) throw new EndOfStreamException(String.Format("End of stream reached with {0} bytes left to read", remaining)); remaining -= read; offset += read; copyInStream.Write(Encoding.Convert(inEncoding, serverEncoding, buf, 0, offset), 0, offset); } } catch (Exception) { copy.Cancel("Undo copy"); throw; } finally { if (copy.CopyStream != null) { copy.CopyStream.Close(); } copy.End(); } } } } заранее извиняюсь за неформатированный код (не знаю как по другому выкладывать) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 31.05.2010, 10:28 |
|
||
|
npgsql и NpgsqlCopyIn() качаю csv в таблицу ... закачивается, но не все данные(((
|
|||
|---|---|---|---|
|
#18+
например у меня было 2 столбца: не докачиваются строки или/и урезается значение во втором столбце т.е. не могу считать таким методом данные полностью((( Кто нибудь закачивал данные таким способом в PostGre ??? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 31.05.2010, 12:49 |
|
||
|
|

start [/forum/topic.php?fid=17&fpage=57&tid=1351286]: |
0ms |
get settings: |
8ms |
get forum list: |
16ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
52ms |
get topic data: |
9ms |
get forum data: |
3ms |
get page messages: |
31ms |
get tp. blocked users: |
1ms |
| others: | 217ms |
| total: | 343ms |

| 0 / 0 |
