Dapper and Varbinary Stream Parameters (max)

I am trying to store a binary blob in a database table and get the output back. The data is stored in the object MemoryStream

. I am trying to store this in a sql server 2012 table using an async request. The call succeeds, but the data does not fit into the column. (for example, I get a 0x0 entry when I ask for it).

Of course, by actually checking the traceback, I can see that dapper is sending 0x0. Memystream has length, am I doing something wrong or doesn't support this scenario? My query string is just a simple insert and returns the id and time of the insert.

I am using the following call

using(var conn=new SqlConnection(_connstr)){

var dynParams = new DynamicParameters();
dynParams.Add("BinaryBlob",
_memoryStream,DbType.Binary,ParameterDirection.Input,-1);
var res = await conn.QueryAsync<MyResultType>(_queryStr, dynParams);
}

      

The query inserts a row and returns a timestamp, but no data has actually been inserted. What am I doing wrong?

+3


source to share


1 answer


Make sure you are looking for the beginning of a memory stream. Streams have positional state. Another approach would be to convert the memory stream to byte [] before trying to store it.

eg.



_memorystream.Seek(0, SeekOrigin.Begin);

      

+3


source







All Articles