Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operand type clash: VARBINARY is incompatible with TEXT #186

Closed
ngvtien opened this issue Jul 16, 2020 · 0 comments · Fixed by #184
Closed

Operand type clash: VARBINARY is incompatible with TEXT #186

ngvtien opened this issue Jul 16, 2020 · 0 comments · Fixed by #184
Labels
Milestone

Comments

@ngvtien
Copy link
Contributor

ngvtien commented Jul 16, 2020

Describe the bug
When insert into 'Text' type column with bytecount of data < 16384 exception is thrown which it shouldn't

To Reproduce
Please provide C#/SQL necessary to reproduce the issue, and steps to follow:

SQL script for test table:
create table [dbo].[test_text_table] (Fragment text not null, CreatedDate datetime default getdate() not null)

C# code

public void TextColumn_With_Data_Length_LessThan_16384_ReturnError()
{
    using (var connection = new AseConnection(ConnectionStrings.Pooled))
    {
        using (var transaction = connection.BeginTransaction())
        {
            using (var fragmentCommand = connection.CreateCommand())
            {
                fragmentCommand.CommandText = "insert into test_text_table (Fragment) VALUES (@fragment)";
                fragmentCommand.CommandType = CommandType.Text;
                fragmentCommand.Transaction = transaction;

                var fragment = new string('x', 4096);
                var p = fragmentCommand.CreateParameter();
                p.ParameterName = @"@fragment";
                p.Value = fragment;
                p.DbType = DbType.String;
                p.Direction = ParameterDirection.Input;

                fragmentCommand.Parameters.Add(p);

                var status = fragmentCommand.ExecuteNonQuery();
                transaction.Rollback();
            }
        }
    }
}

Expected behavior
Should behave similar to the legacy driver where no exception occur.

Environment

  • .NET Framework and Core (All version)
  • AdoNetCore.AseClient nuget package version 0.18.0

Additional context
The way the driver determine the column data type for 'Text' is not reliable in particular using length
{DbType.String, (value, length) => length <= 16384 ? TdsDataType.TDS_LONGBINARY : TdsDataType.TDS_BLOB}

@valente500 valente500 linked a pull request Sep 2, 2020 that will close this issue
@ngvtien ngvtien added this to the 0.19.0 milestone Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants