Link to home
Start Free TrialLog in
Avatar of JAMES
JAMES

asked on

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.

Avatar of Aneesh
Aneesh
Flag of Canada image

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
Avatar of JAMES
JAMES

ASKER

Which is test "correct" variable type to use - text OR image?  Don't I have to serialize if I use text?
Avatar of JAMES

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JAMES

ASKER

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.
>An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Better someone from C# side help you
Thanks for the points. You know I am a back end guy, have no idea of font end..
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
Avatar of JAMES

ASKER

Desp,

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

James.