Search code examples
c#ado.netsap-ase

Sybase (SAP) ASE ADO.NET connection times out for blob inserts


I have a new SAP ASE database with only one table and this table has only three columns - two varchar columns and one image column.

Using the pure ADO.NET provider taken from the developer edition of SAP ASE Database I'm just trying to insert a record into this table with the content of a file - my first trial was with a 3kb file and it worked like a charm. Then, I took a PDF that had around 900kb (less than a 1MB for sure) and the application gave me a timeout; what was uglier then this, was the fact that, somehow, the entire database has blocked - I had to restart the service to make it working again.

So, now let's get to the code - please if there is someone who can lead me into the right direction, I will really appreciate it.

static void Main(string[] args)
        {
            using (AseConnection aseConnection =
                    new AseConnection(
                        "data source=...;initial catalog=...;User ID=...;Password=...;Port=...;ConnectionIdleTimeout=600;CommandTimeOut=0;ConnectionTimeOut=0;Pooling=False;TextSize=10000000")
            )
            {
                aseConnection.Open();
                Console.WriteLine(aseConnection.State.ToString());

                AseCommand setTextSizeCommand = new AseCommand("SET TEXTSIZE 10000000", aseConnection);
                setTextSizeCommand.ExecuteNonQuery();

                byte[] fileContent = File.ReadAllBytes(@"d:\adonet.pdf");
                //byte[] fileContent = File.ReadAllBytes(@"d:\rack.txt");

                AseCommand aseCommand = new AseCommand("insert into xxx(web_id, doc_name, doc_file) values(?, ?, ?)", aseConnection);
                aseCommand.Parameters.Add(0, AseDbType.VarChar, 20).Value = "100";
                aseCommand.Parameters.Add(1, AseDbType.VarChar, 100).Value = "fisier";
                aseCommand.Parameters.Add(2, AseDbType.Image, fileContent.Length).Value = fileContent;
                aseCommand.NamedParameters = false;
                aseCommand.CommandTimeout = 65000;

                aseCommand.ExecuteNonQuery();
            }
        }

The version of the ASE Client dll is 16.0.2.2.

Thank you very much!


Solution

  • In order to fix this issue, I had to create a new database from scratch but this time I gave it more space from the beginning (1GB instead of 6MB - default value).

    Everything is working like a charm now.

    Thank you