Storing Files in the DB via Ent Lib

Feb 24, 2012 at 8:11 PM
Edited Feb 26, 2012 at 7:00 PM

I have written a web application that is using the Ent Lib for database interaction.  The site has a component where a file is uploaded and stored in the database.  At the moment that is a SQL Server database.  I can do this using SQL Server objects based on over examples but the EntLibContrib library can't replicate the same functionality.  Specifically there is an issue where the Object type defaults to a "sql_variant" type in the base objects and this type does not support more than 8000 bytes.  The result is the following error:

 Parameter '@DocFile' exceeds the size limit for the sql_variant datatype.

Does anyone know of a way to store documents in SQL Server using the enterprise library?

I should note that I am using version 4.1 for Oracle compatibility reasons.

Coordinator
Mar 23, 2012 at 2:19 AM

Hi,

sorry for taking so long. Do you still experience the issue? I would however need more details about your actual setup.

Are you targeting SQL Server or Oracle? If your targeting SQL Server, then I would recommend you to post this thread on the EntLib forum since EntLibContrib is specific to other data providers such as Oracle, MySql, etc.

But at first sight, I would try to explicitly specify the DbType when creating the parameters. Also make sure you're using the right type at the database level (most SQL Server "var" types have a maximum length of 8016 bytes).

Regards,

Jeremi

Mar 23, 2012 at 3:09 AM

Hi and thanks for the reply Jeremi,

It is SQL Server that I am trying to work with but I was hoping for a solution that would be platform independent.  In the end I used the SQL client object directly since I could not get the DBType to work.  Basically there is no varbinary equivalent that I could make out.

Thanks,

Peter

Coordinator
Mar 23, 2012 at 4:20 AM

Hi Peter,

indeed, you have to use the Sql client object directly and specify the SqlDbType since DbType.Object is mapped to SqlDbType.Variant as described here http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx.

Cheers,

Jeremi

Mar 23, 2012 at 1:30 PM
Exactly. A bummers but it is what it is.

Thanks again for replying.

On 2012-03-22, at 10:20 PM, jbourgault wrote:

From: jbourgault

Hi Peter,

indeed, you have to use the Sql client object directly and specify the SqlDbType since DbType.Object is mapped to SqlDbType.Variant as described herehttp://msdn.microsoft.com/en-us/library/yy6y35y8.aspx.

Cheers,

Jeremi