DataAction / AdoNetCore.AseClient

AdoNetCore.AseClient - a .NET Core DB Provider for SAP ASE
Apache License 2.0
108 stars 45 forks source link

TDS_BLOBs are not being terminated correctly #170

Closed valente500 closed 4 years ago

valente500 commented 4 years ago

Describe the bug TDS_BLOBs are not being terminated correctly

To Reproduce

  1. Run script

    create table [dbo].[test] (
    text_field text null,
    d datetime null
    )
  2. Execute the following C#

    var value = new string('1', 4097);
    using (var connection = GetConnection())
    {
    connection.Execute("set textsize 1000000");
    var p = new DynamicParameters();
    p.Add("@text_field", value, DbType.String);
    p.Add("@d", new DateTime(2000, 1, 1));
    connection.Execute("insert into [dbo].[test] (text_field, d) values (@text_field, @d)", p);
    }
  3. Observe the C# throws an exception AdoNetCore.AseClient.AseException : The parameter of type 49 did not have a valid value.

When the length of the text_field exceeds 4096 characters, the driver uses TDS_BLOB to send it to the database. The TDS_BLOB is not terminated correctly. This causes an issue only when other parameters follow (like the @d parameter). No issue occurs if there are no parameters following.

Expected behavior The driver should terminate the TDS_BLOB correctly so strings larger than 4096 characters can be inserted. TDS_BLOBs should only be used when the text_field is larger than 8192 characters.

Environment