dcsimg
Results 1 to 8 of 8

Thread: Saving picture/file from client pc to server pc

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Smile Saving picture/file from client pc to server pc

    Good day guys. I have created a small application that records a person's information from the client pc to server pc but i also want to save the person's scanned birth certificate (in jpeg format, probably will not be compressed so its file size will be around 3-4mb). I assume that the application will contain at least 50k to 100k records so saving it directly in the database is not an option as it will make the database file size huge. My workaround is to save it in the server's hard disk and save the path of the image in the database. My question is how do i transfer the scanned image, which will be uploaded in the client PC, to the server?

    I am using VB 2010 and SQL Server 2008 R2 Express and i connect all the workstations via Wifi. Maybe this info will be of help. Thanks in advance.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,488

    Re: Saving picture/file from client pc to server pc

    I would suggest that you forget all that. SQL Server has a FILESATREAM feature that you can enable on the instance that then allows you to save binary data to the database as normal but it will actually be stored external to the database. It is, as far as I know, seamless to the application but prevents the very excessive database growth that you're trying to avoid.

    https://social.msdn.microsoft.com/Se...mark=true&ac=3

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,566

    Re: Saving picture/file from client pc to server pc

    Indeed, that's what I'd suggest too. You would access the image as a field, but on the back end the server will save it as a file outside of the actual mdf itself. What gets stored in the mdf directly is a pointer to the locaton of the image. This will help keep the database size down, but still keep it all together, organized and accessable all the same way.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Saving picture/file from client pc to server pc

    Thanks for the reply. I created a test project and i enabled filestream in my SQL Server/Database by following the steps in this article: Link. I tried saving three records (just 3 images with description) in the DB using this code:

    Code:
        Private Sub SaveDataToFS()
            'Saving Data to FileStream
            Dim conn As New SqlConnection(Server=PAV-PC\SQLEXPRESS;Database=FileSystemTry;Trusted_Connection=True;)
            Dim comm As New SqlCommand()
            conn.Open()
            comm.CommandText = "INSERT INTO PictureTable([Description], [FileData]) VALUES (@Description, @FileData)"
    
            comm.Parameters.AddWithValue("@Description", TextBox1.Text)
            Using ms As New IO.MemoryStream
                PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
                Dim data1 As Byte() = ms.GetBuffer
                comm.Parameters.AddWithValue("@FileData", data1)
            End Using
    
            comm.Connection = conn
            comm.ExecuteNonQuery()
            conn.Close()
    
            MsgBox("ok")
        End Sub
    and it saved succesfully. But when i looked at the location where the images are saved, two of the images doubled in file size but the other remained the same. I tried deleting the three sample data in SQL server but the images still remained in the folder. I also tried editing a record successfully but instead of overwriting the existing picture file, it added another one.

    My questions are:
    1. When saving the data, i tried a different approach rather than following what the codeproject article said and yet it worked. Do i retain using my code or do i really need to follow what the codeproject article said?
    2. Why did some of the images doubled in file size but others remained the same?
    3. Why are the images still in the filestream folder even though i deleted the record?
    Last edited by rptdelosreyes; Mar 3rd, 2015 at 07:53 AM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Saving picture/file from client pc to server pc

    help please

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Saving picture/file from client pc to server pc

    help please

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Saving picture/file from client pc to server pc

    please help me

  8. #8
    Lively Member
    Join Date
    Aug 2011
    Posts
    66

    Re: Saving picture/file from client pc to server pc

    Do you have the hostname or ip of the server? you can move the file through network like you move files locally.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width