Uploading large files to sql azure using handler

3 posts, 0 answers
  1. Chris
    Chris avatar
    3 posts
    Member since:
    Sep 2015

    Posted 31 Aug 2015 Link to this post

    I'm using a handler to upload directly into my azure sql db.

    Have adjusted web web config to allow 100mb and applicationhost config to allow everything seems to work ok. Files of various sizes upload fine until I try a file of 18MB. No errors reported, I get the little green light on the uploader but nothing actually gets into the DB.

    Unsure where to start looking as no error gets reported.

    Any ideas?

    Handler code below if it helps....

     

    <%@ WebHandler Language="C#" Class="Handler" %>
    using System;
    using System.Web;
    using Telerik.Web.UI;
    public class Handler : AsyncUploadHandler
    {
    protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
    {
    System.IO.Stream fileStream = file.InputStream;
    byte[] attachmentBytes = new byte[fileStream.Length];
    fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length));
    System.Data.SqlClient.SqlConnection conn = null;
    try
    {
    try
    {
    conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["etb"].ConnectionString);
    conn.Open();
    System.Data.SqlClient.SqlCommand insertCommand = new System.Data.SqlClient.SqlCommand("INSERT INTO STAFF_DOC(FILENAME,FILESIZE,DOC,CONTENT_TYPE,SHORT_DESC,STAFF_ID) VALUES( @FileName, @FileSize, @FileData, @ContentType,'test',26)", conn);
    insertCommand.Parameters.Add("@FileName", System.Data.SqlDbType.VarChar).Value = file.FileName;
    insertCommand.Parameters.Add("@FileData", System.Data.SqlDbType.VarBinary).Value = attachmentBytes;
    insertCommand.Parameters.Add("@ContentType", System.Data.SqlDbType.VarChar).Value = file.ContentType ;
    insertCommand.Parameters.Add("@FileSize", System.Data.SqlDbType.VarChar).Value = attachmentBytes.Length;
    int queryResult = insertCommand.ExecuteNonQuery();
    }
    catch (Exception ex){}
    }
    finally
    {
    if (conn != null)
    {fileStream.Close();
    conn.Close();}
    }
    return CreateDefaultUploadResult<UploadedFileInfo>(file);
    }

     

     

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 03 Sep 2015 Link to this post

    Hi Chris,

    Is Process() method executed? What happens when you debug this code? 

    I'm just curious why don't you use Azure Storage instead Azure SQL? 


    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    3 posts
    Member since:
    Sep 2015

    Posted 08 Sep 2015 in reply to Hristo Valyavicharski Link to this post

    Hi Hristo, thanks for the response. It looks like it's a server timeout happening. I've followed the recommendations on web.config etc, but I'll have go over it again.

    This is part of a relational database app used to use SQL 2012 on premises so migrated to sql azure.

    Thanks for the help.

Back to Top