I am new to dotConnect and I am trying to make use of PgSqlLargeObjec to store files.
The creation of the large object fails when I call: largeObject.Create();
This call throws a Devart.Data.PostgreSql.PgSqlException with a message"Read less bytes than expected" (please see below for details).
It looks like largeObject.Create() call closes the connection, because the transaction.Rollback() fails too with an exception indicating "Connection must be open"
I have tried both protocol versions in the connection string, but the result is the same. Not sure what I am doing wrong.
I have tried the same functionality with Npgsql data provider and it works fine for the same PostgreSql DB (EnterpriseDB 9.2.2.4)
The following is the test code I am using:
Code: Select all
[TestMethod]
public void TestPgSql_insert_LargeObject_with_db_transaction()
{
using (PgSqlConnection connection = new PgSqlConnection(connectionString))
{
connection.Open();
//LargeObject requires a transaction
using (PgSqlTransaction transaction = connection.BeginTransaction())
{
try
{
using (FileStream backupStream = File.OpenRead(filePath))
{
byte[] buffer = new byte[1024];
backupStream.Seek(0, SeekOrigin.Begin);
int oid;
using (PgSqlLargeObject largeObject = new PgSqlLargeObject(connection))
{
oid = largeObject.Create();
largeObject.Open();
int bytesRead;
while ((bytesRead = backupStream.Read(buffer, 0, buffer.Length)) != 0)
{
largeObject.Write(buffer, 0, bytesRead);
}
largeObject.Close();
}
}
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
}
}
---------------------------------------------------------------
Devart.Data.PostgreSql.PgSqlException was caught
HResult=-2147467259
Message=Read less bytes than expected.
Source=Devart.Data.PostgreSql
ErrorCode=-2147467259
LineNumber=0
Position=0
StackTrace:
at Devart.Common.am.d(Exception A_0)
at Devart.Data.PostgreSql.ab.d(Exception A_0)
at Devart.Common.x.d(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Common.z.a(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.PostgreSql.y.c(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.PostgreSql.y.f()
at Devart.Data.PostgreSql.am.a(Boolean A_0, Boolean A_1, Char A_2, Boolean A_3)
at Devart.Data.PostgreSql.am.b(Boolean A_0, Boolean A_1)
at Devart.Data.PostgreSql.am.c(Boolean A_0)
at Devart.Data.PostgreSql.af.a(Int32 A_0, Byte[][] A_1, Int32[] A_2, Int32[] A_3, Byte[] A_4, Int32 A_5)
at Devart.Data.PostgreSql.w.a(Int32 A_0, Byte[][] A_1, Int32[] A_2, Int32[] A_3, Byte[] A_4, Int32 A_5)
at Devart.Data.PostgreSql.w.a(Int32[] A_0)
at Devart.Data.PostgreSql.t.b()
at Devart.Data.PostgreSql.PgSqlLargeObject.Create()
at PostgreSqlDataProviderTests.DevartDotConnectProviderTests.TestPgSql_insert_LargeObject_with_db_transaction() in c:\Tilemachos\LocalGit\PostgreSqlDataProviderTests\PostgreSqlDataProviderTests\DevartDotConnectProviderTests.cs:line 53
InnerException: Devart.Common.ad
HResult=-2146233088
Message=Read less bytes than expected.
Source=Devart.Data.PostgreSql
StackTrace:
at Devart.Common.i.c(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Common.x.d(Byte[] A_0, Int32 A_1, Int32 A_2)
InnerException:
Thanks in advance for your help.
Regards,
Tilemachos