Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Images, SQL and C# -PLEASE HELP

Images, SQL and C# -PLEASE HELP

Scheduled Pinned Locked Moved C#
databasegraphicshelpcsharpsysadmin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Greenall
    wrote on last edited by
    #1

    Hi, Im developing a project which consists of a client which sends images to a server. The server must store these images in a database, and I am having a multitude of problems. I first tried creating a web-service which accepted the image as a parameter in a web method, but it would appear that System.Drawing.Image.Bitmap is not serializable - it generates an XML Serialization error. I then thought I would try and access the database directly and just store add images using an INSERT command, but I am getting an error message that the 'object' (I believe this refers to the image object) must implement IConvertable. Can anyone help me at all - I've been trying to sort this for the last week, and I really need to sort it. Thanks in advance Peter

    H J 2 Replies Last reply
    0
    • P Peter Greenall

      Hi, Im developing a project which consists of a client which sends images to a server. The server must store these images in a database, and I am having a multitude of problems. I first tried creating a web-service which accepted the image as a parameter in a web method, but it would appear that System.Drawing.Image.Bitmap is not serializable - it generates an XML Serialization error. I then thought I would try and access the database directly and just store add images using an INSERT command, but I am getting an error message that the 'object' (I believe this refers to the image object) must implement IConvertable. Can anyone help me at all - I've been trying to sort this for the last week, and I really need to sort it. Thanks in advance Peter

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Adding images to a database has been covered numerous times in the past. Please use the Search Comments link above and search for previous solutions, such as these found in a recent thread: http://www.codeproject.com/script/comments/forums.asp?msg=704229&forumid=1649&XtraIDs=1649&searchkw=database+image&sd=10%2F22%2F2003&ed=1%2F20%2F2004#xx704229xx[^]. As far as sending images (either Image orBitmap, a derivative of Image, neither of which are serializable), most implementations use a MemoryStream (or another Stream like FileStream, especially if the images were already saved to disk) to save the images to a buffer (a byte[] array), which is serializable (since Array is serializable). Either way, once your image gets deserialized on the server, you still have to insert it into the database. Depending on your implementation requirements, you might actually be better off storing the image on the file system and inserting a file reference (like the URL to access it remotely, which you can always use Page.MapPath to get the file system path) into the database. This way, if you want to display the images in a web page, you don't have to extract them first or use a page to dynamically extract and stream them out using a different content-type than a normal page (ex: .aspx file). For a good example using SQL Server, see C# Photo Album Viewer[^]. If this is for use on a server, I highly recommend that you do not use Access. Use a real RDBMS that implements ACID properties like SQL Server or the MSDE (a connection-limited version of SQL Server). You can find more information about SQL Server at http://www.microsoft.com/sql/default.asp[^] or download the MSDE for free at

      P 1 Reply Last reply
      0
      • H Heath Stewart

        Adding images to a database has been covered numerous times in the past. Please use the Search Comments link above and search for previous solutions, such as these found in a recent thread: http://www.codeproject.com/script/comments/forums.asp?msg=704229&forumid=1649&XtraIDs=1649&searchkw=database+image&sd=10%2F22%2F2003&ed=1%2F20%2F2004#xx704229xx[^]. As far as sending images (either Image orBitmap, a derivative of Image, neither of which are serializable), most implementations use a MemoryStream (or another Stream like FileStream, especially if the images were already saved to disk) to save the images to a buffer (a byte[] array), which is serializable (since Array is serializable). Either way, once your image gets deserialized on the server, you still have to insert it into the database. Depending on your implementation requirements, you might actually be better off storing the image on the file system and inserting a file reference (like the URL to access it remotely, which you can always use Page.MapPath to get the file system path) into the database. This way, if you want to display the images in a web page, you don't have to extract them first or use a page to dynamically extract and stream them out using a different content-type than a normal page (ex: .aspx file). For a good example using SQL Server, see C# Photo Album Viewer[^]. If this is for use on a server, I highly recommend that you do not use Access. Use a real RDBMS that implements ACID properties like SQL Server or the MSDE (a connection-limited version of SQL Server). You can find more information about SQL Server at http://www.microsoft.com/sql/default.asp[^] or download the MSDE for free at

        P Offline
        P Offline
        Peter Greenall
        wrote on last edited by
        #3

        Thanks once again for your help Heath!! I did use the search facility for the message boards and general articles, but I was unable to find something which actually stored the image in the database, not just a referance. I will consider doing this though in my implementation. I am using MS SQL Server - not access, and I will carefully go through the mentioned articles. Thankyou once again - I will battle on! Peter

        1 Reply Last reply
        0
        • P Peter Greenall

          Hi, Im developing a project which consists of a client which sends images to a server. The server must store these images in a database, and I am having a multitude of problems. I first tried creating a web-service which accepted the image as a parameter in a web method, but it would appear that System.Drawing.Image.Bitmap is not serializable - it generates an XML Serialization error. I then thought I would try and access the database directly and just store add images using an INSERT command, but I am getting an error message that the 'object' (I believe this refers to the image object) must implement IConvertable. Can anyone help me at all - I've been trying to sort this for the last week, and I really need to sort it. Thanks in advance Peter

          J Offline
          J Offline
          Jose Fco Bonnin
          wrote on last edited by
          #4

          You can convert it to a byte[] before send to the server and then store it directly. public StorePhoto(byte[] photoContent) { ....... SqlParameter param1 = new SqlParameter("@photo",SqlDbType.Image); param1.Direction = ParameterDirection.Input; param1.Value = photoContent; ....... }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups