This is a migrated thread and some comments may be shown as answers.

Uploading large files to sql azure using handler

2 Answers 70 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Sep 2015, 03:39 AM

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 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 03 Sep 2015, 01:57 PM
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
0
Chris
Top achievements
Rank 1
answered on 08 Sep 2015, 09:36 AM

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.

Tags
AsyncUpload
Asked by
Chris
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Chris
Top achievements
Rank 1
Share this question
or