Saving an image to SQL Server's image datatype

Discussion in 'ASP .Net' started by Nathan Sokalski, Jul 17, 2008.

  1. I am using ASP.NET 2.0, and need to know how to save and use an image that
    is stored in an SQL Server image datatype. How can I do this using ASP.NET?
    Thanks.
     
    Nathan Sokalski, Jul 17, 2008
    #1
    1. Advertising

  2. Stuart Ainsworth, Jul 17, 2008
    #2
    1. Advertising

  3. Nathan Sokalski

    Linchi Shea Guest

    A well-kept secret :)

    "TheSQLGuru" wrote:

    > Or search.live.com. :)
    >
    > --
    > Kevin G. Boles
    > Indicium Resources, Inc.
    > SQL Server MVP
    > kgboles a earthlink dt net
    >
    >
    > "Stuart Ainsworth" <> wrote in message
    > news:...
    > On Jul 17, 11:38 am, "Nathan Sokalski" <>
    > wrote:
    > > I am using ASP.NET 2.0, and need to know how to save and use an image that
    > > is stored in an SQL Server image datatype. How can I do this using
    > > ASP.NET?
    > > Thanks.

    >
    > google is your friend...
    >
    > http://www.codeproject.com/KB/web-image/PicManager.aspx
    > http://aspalliance.com/articleViewer.aspx?aId=138
    > http://bytes.com/forum/thread287108.html
    >
    > HTH,
    > Stu
    >
    >
    >
     
    Linchi Shea, Jul 18, 2008
    #3
  4. Nathan Sokalski

    Rahul Guest

    On Jul 18, 8:19 am, Linchi Shea <>
    wrote:
    > A well-kept secret :)
    >
    >
    >
    > "TheSQLGuru" wrote:
    > > Or search.live.com.  :)

    >
    > > --
    > > Kevin G. Boles
    > > Indicium Resources, Inc.
    > > SQL Server MVP
    > > kgboles a earthlink dt net

    >
    > > "Stuart Ainsworth" <> wrote in message
    > >news:...
    > > On Jul 17, 11:38 am, "Nathan Sokalski" <>
    > > wrote:
    > > > I am using ASP.NET 2.0, and need to know how to save and use an image that
    > > > is stored in an SQL Server image datatype. How can I do this using
    > > > ASP.NET?
    > > > Thanks.

    >
    > > google is your friend...

    >
    > >http://www.codeproject.com/KB/web-image/PicManager.aspx
    > >http://aspalliance.com/articleViewer.aspx?aId=138
    > >http://bytes.com/forum/thread287108.html

    >
    > > HTH,
    > > Stu- Hide quoted text -

    >
    > - Show quoted text -


    Hi,
    Saving image in database is not a good idea, this activity create
    unnessary bulky database.
    Ok.. If you want to save image in the database, you can use varbinary
    datatype insteda of image, microsoft will remove image datatype in
    there earlier version.

    Rahul
     
    Rahul, Jul 18, 2008
    #4
  5. Nathan Sokalski

    ML Guest

    ML, Jul 18, 2008
    #5
  6. Nathan Sokalski

    Linchi Shea Guest

    > Saving image in database is not a good idea, this activity create
    > unnessary bulky database.


    It depends. If you have a large number of small images, you may be better
    off storing them in the database. If you have a relatively small number of
    large images, it may be better to keep them in the filesytem. If you want to
    stream from these images, keep them outside of the database.

    Linchi

    "Rahul" wrote:

    > On Jul 18, 8:19 am, Linchi Shea <>
    > wrote:
    > > A well-kept secret :)
    > >
    > >
    > >
    > > "TheSQLGuru" wrote:
    > > > Or search.live.com. :)

    > >
    > > > --
    > > > Kevin G. Boles
    > > > Indicium Resources, Inc.
    > > > SQL Server MVP
    > > > kgboles a earthlink dt net

    > >
    > > > "Stuart Ainsworth" <> wrote in message
    > > >news:...
    > > > On Jul 17, 11:38 am, "Nathan Sokalski" <>
    > > > wrote:
    > > > > I am using ASP.NET 2.0, and need to know how to save and use an image that
    > > > > is stored in an SQL Server image datatype. How can I do this using
    > > > > ASP.NET?
    > > > > Thanks.

    > >
    > > > google is your friend...

    > >
    > > >http://www.codeproject.com/KB/web-image/PicManager.aspx
    > > >http://aspalliance.com/articleViewer.aspx?aId=138
    > > >http://bytes.com/forum/thread287108.html

    > >
    > > > HTH,
    > > > Stu- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    > Hi,
    > Saving image in database is not a good idea, this activity create
    > unnessary bulky database.
    > Ok.. If you want to save image in the database, you can use varbinary
    > datatype insteda of image, microsoft will remove image datatype in
    > there earlier version.
    >
    > Rahul
    >
     
    Linchi Shea, Jul 18, 2008
    #6
  7. OK, but regardless of my choice, I need to know what my code should look
    like to get them into and out of the DB. I have used the FileUpload control
    before to upload a file to the file system, but I have never put an image
    (or any other type of file) into a database. If you know of any examples, it
    would be extremely helpful. Thanks.

    Nathan Sokalski

    http://www.nathansokalski.com/

    "Linchi Shea" <> wrote in message
    news:...
    >> Saving image in database is not a good idea, this activity create
    >> unnessary bulky database.

    >
    > It depends. If you have a large number of small images, you may be better
    > off storing them in the database. If you have a relatively small number of
    > large images, it may be better to keep them in the filesytem. If you want
    > to
    > stream from these images, keep them outside of the database.
    >
    > Linchi
    >
    > "Rahul" wrote:
    >
    >> On Jul 18, 8:19 am, Linchi Shea <>
    >> wrote:
    >> > A well-kept secret :)
    >> >
    >> >
    >> >
    >> > "TheSQLGuru" wrote:
    >> > > Or search.live.com. :)
    >> >
    >> > > --
    >> > > Kevin G. Boles
    >> > > Indicium Resources, Inc.
    >> > > SQL Server MVP
    >> > > kgboles a earthlink dt net
    >> >
    >> > > "Stuart Ainsworth" <> wrote in message
    >> > >news:...
    >> > > On Jul 17, 11:38 am, "Nathan Sokalski" <>
    >> > > wrote:
    >> > > > I am using ASP.NET 2.0, and need to know how to save and use an
    >> > > > image that
    >> > > > is stored in an SQL Server image datatype. How can I do this using
    >> > > > ASP.NET?
    >> > > > Thanks.
    >> >
    >> > > google is your friend...
    >> >
    >> > >http://www.codeproject.com/KB/web-image/PicManager.aspx
    >> > >http://aspalliance.com/articleViewer.aspx?aId=138
    >> > >http://bytes.com/forum/thread287108.html
    >> >
    >> > > HTH,
    >> > > Stu- Hide quoted text -
    >> >
    >> > - Show quoted text -

    >>
    >> Hi,
    >> Saving image in database is not a good idea, this activity create
    >> unnessary bulky database.
    >> Ok.. If you want to save image in the database, you can use varbinary
    >> datatype insteda of image, microsoft will remove image datatype in
    >> there earlier version.
    >>
    >> Rahul
    >>
     
    Nathan Sokalski, Jul 24, 2008
    #7
  8. > like to get them into and out of the DB. I have used the FileUpload control
    > before to upload a file to the file system, but I have never put an image
    > (or any other type of file) into a database. If you know of any examples, it
    > would be extremely helpful.


    WHICH file upload control? Some of them have a built-in SaveToDatabase-type
    method. This is a component I used to use in "Classic ASP" development,
    which had this functionality built in:

    http://www.aspupload.com/manual_db.html

    If you are using .NET then Google yields some results fairly quickly:

    http://www.eggheadcafe.com/articles/20030624.asp

    http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx

    http://blog.codebeach.com/2008/02/how-to-save-image-in-sql-server.html

    (What does this have to do with fulltext / clients?)
     
    Aaron Bertrand [SQL Server MVP], Jul 24, 2008
    #8
  9. Nathan Sokalski

    Hans Kesting Guest

    Nathan Sokalski laid this down on his screen :
    > OK, but regardless of my choice, I need to know what my code should look like
    > to get them into and out of the DB. I have used the FileUpload control before
    > to upload a file to the file system, but I have never put an image (or any
    > other type of file) into a database. If you know of any examples, it would be
    > extremely helpful. Thanks.
    >


    I use a store procedure with a parameter of type "image". Inside that
    procedure you can use that variable to insert into the table.

    When calling that stored procedure from the .Net code, I use parameters
    to supply the data. The image-type parameter is then filled with the
    byte[] containing that file.

    Hans Kesting
     
    Hans Kesting, Jul 25, 2008
    #9
  10. Nathan Sokalski

    steve Guest

    Hey Nathan,

    An article on Large Object Storage in a Database or a Filesystem
    http://research.microsoft.com/research/pubs/view.aspx?msr_tr_id=MSR-TR-2006-45


    If you want to know how I do it:

    I use and Image.aspx page and stream the image to that page then in and
    other page i use and image controle and set the image.aspx page as image
    path.
    To get the connection I use linq in the example I make the query with linq
    but that is not fast with large tables so you’re better off using stored
    procedures with linq.

    example:
    The page with the image control
    imgImageControl.ImageUrl = "Image.aspx?Id=2";


    The image.aspx page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Try
    Dim objNV As NameValueCollection
    Dim pic() As Byte = Nothing
    Dim strID As String = ""
    objNV = Request.QueryString()
    If Not objNV.Count = 0 Then
    strID = objNV.Item("ID")
    Else
    pic = Session("Id")
    If pic Is Nothing Then
    strID = User.Identity.Name.ToString()
    End If
    End If
    If Not strID = "" Then
    Dim db As New
    myDB(ConfigurationManager.ConnectionStrings("sql1").ConnectionString)
    Dim Updateprofiel = (From p In db.Profiels Where p.Prof_ID =
    strID Select p.Foto).ToList()(0)
    If Not Updateprofiel Is Nothing Then
    pic = Updateprofiel.ToArray()
    End If
    db.Connection.Close()
    End If
    If Not pic Is Nothing Then
    Response.ContentType = "image/jpeg"
    Response.OutputStream.Write(pic, 0, pic.Length)
    End If
    Catch ex As Exception
    MsgBox(ex.ToString, MsgBoxStyle.Critical, "Big error run
    away!!!!!")
    End Try

    End Sub

    steve


    "Nathan Sokalski" wrote:

    > I am using ASP.NET 2.0, and need to know how to save and use an image that
    > is stored in an SQL Server image datatype. How can I do this using ASP.NET?
    > Thanks.
    >
    >
    >
     
    steve, Aug 3, 2008
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dna
    Replies:
    1
    Views:
    1,310
  2. Matt Mercer

    Re: Search SQL image datatype

    Matt Mercer, Sep 22, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    753
    Steve C. Orr [MVP, MCSD]
    Sep 22, 2004
  3. Replies:
    1
    Views:
    643
    =?iso-8859-1?Q?Guillermo_Gonz=E1lez_A.?=
    Jul 21, 2005
  4. nkunapa
    Replies:
    4
    Views:
    6,766
    nkunapa
    Aug 10, 2005
  5. Jeff
    Replies:
    2
    Views:
    1,197
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 16, 2007
Loading...

Share This Page