How to store a memorystream in sql server

I will cross-post this in the sql server forum also

Hi,

I have a control that returns me a stream (memorystream) and I wish to store this variable length (possibly sometimes more than 8000 bytes) data in a sql server table.

The question is what colum type should i use (i have seen people mention image and text) and how I actually get the stream into the column ie. I know how all the sql stuff works and I am using a stored proc with parameters so the question is do I need to cast the stream before assigning it to the sql parameter??

Many thanks.

James.

JAMESAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
text : will store the data in unicode format
image: will store the data in binary

I am not sure about how the values will come from memory stream (if it is in binary, use image;else text)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
You can use the Text/image variable type ;
>do I need to cast the stream before assigning it to the sql parameter??
Not needed, you will be able to store as it is in the current form
0
 
JAMESAuthor Commented:
Which is test "correct" variable type to use - text OR image?  Don't I have to serialize if I use text?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
JAMESAuthor Commented:
Also if I try and assign the memorystream directly to either the text or image types and execute my query I receive the error:-

An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll
Additional information: Object must implement IConvertible.
0
 
JAMESAuthor Commented:
OK - i had to use the .GetBuffer() method from the memory stream and now it seems to work also using an sql server image type.

Strictly speaking you didnt give me the answer but it was reassuring knowing which way to go so i will award the points anyway.

Cheers.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
>An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Better someone from C# side help you
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Thanks for the points. You know I am a back end guy, have no idea of font end..
0
 
Fahad MukhtarDistinguished EngineerCommented:
Although the question has been answered but you will surely get help from these links:
http://www.codeproject.com/cs/database/images2db.asp
http://www.codeproject.com/cs/database/UploadPicturesSQLServer.asp
0
 
JAMESAuthor Commented:
Desp,

Great links - I am sorry the question has now been closed but thank you anyway.

James.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.