Upload Images to Database

Discussion in 'General troubleshooting' started by Photonormal, Jul 3, 2013.

  1. I recently contacted Winhost support but was told to try and get a solution in the forums section.

    I have a website that has an administration section that uploads images, converts them to binary and stores the images in a database. All of a sudden (it started a couple months ago), I am unable to do this, getting the following error:

    /Administration/NaturePhotographPhotoAdd.aspx.cs
    btnSubmit_OnClick
    Parameter is not valid.

    System.Drawing
    at System.Drawing.Bitmap..ctor(String filename) at Photonormal.Administration.NaturePhotographPhotoAdd.btnSubmit_OnClick(Object sender, EventArgs e) in G:\Photonormal\Administration\NaturePhotographPhotoAdd.aspx.cs:line 68
    7/1/2013 5:30:18 PM

    I have my trust level set to "Full" and the same code works locally on my own computer but when I try to do this on my site hosted by Winhost, I get the above mentioned error.
    Winhost states they reset my "ACL" permissions.
    Would anyone know something for me to check? I have a hard time believing it is code, as I cannot reproduce the error in DEBUG mode inside Visual Studio.
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    Check line 68 of your code behind file. Did you modify a stored procedure in your database recently? Check that the parameter type in your code matches that of your database.
     
  3. Elshadriel: Thank you for the response, but I haven't changed anything in months and all the same code works when I run it locally so I wouldn't think it is something with parameters.

    Line 68 in my code-behind calls an object that uploads the images to the database.

    When I debug the code, every parameters is right with no issues. When I use the same image with the same values on the production site (Winhost servers), this error occurs but at that point, I am unable to debug line-by-line like I locally.
     
    Last edited by a moderator: Oct 14, 2015
  4. Elshadriel

    Elshadriel Winhost Staff

    Could you post the full error message? There might be clues on what the problem might be. Also, why is the error referencing the G: drive?
     
  5. I did post the full error message:

    /Administration/NaturePhotographPhotoAdd.aspx.cs
    btnSubmit_OnClick
    Parameter is not valid.

    System.Drawing
    at System.Drawing.Bitmap..ctor(String filename) at Photonormal.Administration.NaturePhotographPhotoAdd.btnSubmit_OnClick(Object sender, EventArgs e) in G:\Photonormal\Administration\NaturePhotographPhotoAdd.aspx.cs:line 68
    7/1/2013 5:30:18 PM

    This is the error that is thrown in my try....catch clause.

    As to it referencing the G:\, this is the location where the code was compiled and used in the debug file (.pdb) which is created when you compile the project inside Visual Studio so that when errors occur, you can reference the line numbers and information. It is simply telling you where the code was compiled. Had I compiled the code on C:\Applications\, then this would be stored and shown when an error occurs.
     
  6. Elshadriel

    Elshadriel Winhost Staff

    I wasn't aware that the error was thrown by your try/catch clause. I thought it might be a system error message. Doing some research indicates the problem might be due to a memory issue, and number of posts suggest disposing your Bitmap object correctly. You might want to try that.
     
  7. First: I want to thank you for the help. I do appreciate it.

    I would agree with you except for a few things:
    1). I can upload hundreds of images locally with no issue.
    2). The first time I try to run this code on Winhost's servers, it has a problem, not the 10th image so I wouldn't have even gotten to any code to dispose the object. Added to that, .Net has a garbage collection routine that does this for you anyway.

    From what I am reading on it, I would have to agree with you. It most likely is a memory issue, but a memory issue on the servers on which it is running, which would be Winhost.

    Is it possible I am hitting a memory limit for my site? Is there anyway to know the memory allocated to my site?
     
    Last edited by a moderator: Oct 14, 2015
  8. rum

    rum Winhost Staff

    The memory limits on our shared production web servers are as follows: 100 mb on Basic site plans, 200 mb on Max site plans, and 300 mb on Ultimate site plans. In case the application exceeds the memory limit, the application pool recycles. Our system administrators can check the event logs on the server and find out if your application pool is being recycled due to high memory usage. Please open a ticket with support department with this specific request.
     
  9. Elshadriel

    Elshadriel Winhost Staff

    According to a poster on these links:

    http://stackoverflow.com/questions/14099246/system-drawing-parameter-is-not-valid
    http://stackoverflow.com/questions/6333681/c-sharp-parameter-is-not-valid-creating-new-bitmap

    The Bitmap object uses unmanaged resources, so you might have to explicitly call the Dispose() method. The .NET garbage collection routine might not kick in. I haven't programmed in a while, so I'm not sure if this is the case. Regarding your first point, it probably works locally because you have access to the all the memory on your machine. Try imposing the limits rum described above locally. If it doesn't work, then you know it's a memory issue.
     
  10. Elshadriel:

    Thank you so much for the help. I do greatly appreciate it.....
     
  11. I placed .Dispose() on the call, with no change in the error.

    I resized my test image to 10x7, which is a 16kb file, which is about as small as I can get an image, and get the same error.

    I cannot believe a 10x7 image of 16KB is taking over 100MB of memory.
     

Share This Page