Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1215
  • Last Modified:

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.

0
JAMES
Asked:
JAMES
  • 4
  • 4
1 Solution
 
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now