Issue with PgSqlLargeObject - Read less bytes than expected

Issue with PgSqlLargeObject - Read less bytes than expected

Postby Tilemachos » Fri 19 Apr 2013 16:24

Hi,

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;
                    }
                }
            }
        }


The following is the exception i am getting
---------------------------------------------------------------
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
Tilemachos
 
Posts: 3
Joined: Fri 19 Apr 2013 15:37

Re: Issue with PgSqlLargeObject - Read less bytes than expected

Postby Pinturiccio » Tue 23 Apr 2013 14:44

We could not reproduce the issue. Could you please specify the following?
1. the exact version and edition of dotConnect for PostgreSQL. You can check the version and edition of dotConnect for PostgreSQL by selecting About dotConnect for PostgreSQL from the PostgreSQL sub-menu of the Tools menu in Visual Studio;
2. the name and version of the EnterpriseDB company product;
3. your connection string (roughly, without credentials).
Pinturiccio
Devart Team
 
Posts: 1978
Joined: Wed 02 Nov 2011 09:44

Re: Issue with PgSqlLargeObject - Read less bytes than expected

Postby Tilemachos » Tue 23 Apr 2013 19:47

Hi,

Please find below the additional requested information. Please note I am using a trial version of dotConnect for PostgreSql:

The Devart product version is:
dotConnect for PostgreSql (Trial Edition)
version: 6.6.224.0


This is an EnterpriseDB product located at:
http://www.enterprisedb.com/downloads/postgres-postgresql-downloads

The current DB Server installation is running on Linux
The installed server version string: EnterpriseDB 9.2.2.4 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit


The connection string is
<add name="devart_postgresql_db"
connectionString="User Id=user;Password=user;Host=1.1.4.3;Port=9999;Database=postgresqldb;Protocol=Ver20;Persist Security Info=True;Schema=user" />


I hope it helps.

Regards,
Tilemachos
Tilemachos
 
Posts: 3
Joined: Fri 19 Apr 2013 15:37

Re: Issue with PgSqlLargeObject - Read less bytes than expected

Postby Pinturiccio » Thu 25 Apr 2013 14:53

We could not reproduce the issue with EnterpriseDB 9.2.1.3 (this is the latest version available for download on the EnterpriseDB company website).

Try performing the following steps and inform us about the results:
1. Execute a simple select query against your database. For example, the following one:
Code: Select all
PgSqlConnection connection = new PgSqlConnection(connectionString);
connection.Open();
PgSqlCommand comm = new PgSqlCommand("select * from some table", connection);
PgSqlDataReader reder = comm.ExecuteReader();
while (reder.Read())
{
    for (int i = 0; i < reder.FieldCount; i++)
        Console.Write(reder.GetValue(i) + "\t");
    Console.WriteLine();
}

2. If you have a PostgreSQL server on another computer, try to connect to this server and run your application. Does your application run on it?

3. Create a console application with the code you have provided in the first post. Does the console application run?
Pinturiccio
Devart Team
 
Posts: 1978
Joined: Wed 02 Nov 2011 09:44

Re: Issue with PgSqlLargeObject - Read less bytes than expected

Postby Tilemachos » Thu 25 Apr 2013 15:20

Hello,

I can successfully execute simple select queries. I have a sample test application where simple queries work just fine using dotConnect data provider, and also LinqConnect. I can select/delete/update tables in the existing database without issues with both dotConnect or LinqConnect. PgSqlLargeObject calls is the only feature failing at this point.

Unfortunately, we have only one instance of EnterpriseDB at the moment, so it is not possible to test the code on a different DB server.

Regards,
Tilemachos
Tilemachos
 
Posts: 3
Joined: Fri 19 Apr 2013 15:37

Re: Issue with PgSqlLargeObject - Read less bytes than expected

Postby Pinturiccio » Tue 07 May 2013 15:24

We have answered you via e-mail.
Pinturiccio
Devart Team
 
Posts: 1978
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL