Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Firebird: Insert with blob.Length > 4000 fails with System.ArgumentOutOfRangeException

Open bauradar opened this issue 1 year ago • 2 comments

Hello,

I am using Dapper with Firebird for some time and its like a charm. Unfortunatly I am facing a problem, when I try to Insert a record with text into a blob, when the length of the text > 4000.

I loaded the lastest version of Dapper and the Firebird .net provider and included the debug symbols.

  • .net 4.8
  • Dapper 2.1.35
  • Firebird .net provider 10.3.1

When I hit this line in my code baustelle.BaustellenID = fbCon.QuerySingle(insertorupdateBaustellen, baustelle); I step into the Daper code.

grafik

grafik

The final exception is this: at FirebirdSql.Data.FirebirdClient.FbParameter.set_Size(Int32 value) in //src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbParameter.cs:line 77 at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader) in /_/Dapper/CommandDefinition.cs:line 144 at Dapper.SqlMapper.QueryRowImpl[T](IDbConnection cnn, Row row, CommandDefinition& command, Type effectiveType) in /_/Dapper/SqlMapper.cs:line 1271 at Dapper.SqlMapper.QuerySingle[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable1 commandTimeout, Nullable`1 commandType) in //Dapper/SqlMapper.cs:line 878 at fbTest.Program.Main(String[] args) in D:\Software Test\fbTest\Program.cs:line 70

When I use ADO standard method with command and parameters it works without problems.

Check your library version, and try updating To help, we're going to need to know your library version. If it isn't the latest: go do that - it might fix the problem, and even if it doesn't: you're going to need to update if we find a problem and fix it, so you might as well get ready for that now.

How to reproduce: Insert a new record into the database with a text for the blob, where the text has a length > 4000

The actual behavoir: exception as described above The needed behavior: successfull insert

Thanks

Niko

bauradar avatar Dec 07 '24 16:12 bauradar

I was also in contact with the developer of the Firebird .net provider. His assessment: "Guessing by the line number, looks like Dapper is setting negative value for Size property of FbParameter, which looks suspicious. Maybe it is setting -1 as an unknown value… Sadly the docs https://learn.microsoft.com/en-us/dotnet/api/system.data.common.dbparameter.size?view=net-8.0#system-data-common-dbparameter-size does not really specify expected values. "

bauradar avatar Jan 17 '25 12:01 bauradar

To many providers, -1 means "max", which accepts most values. In the AOT work, [DbValue(...)] allows Size to be controlled explicitly, or in vanilla Dapper, there is DbString for values, which again allows the Size to be controlled.

mgravell avatar Jan 17 '25 12:01 mgravell