2014-12-27 83 views
1

當文件大小爲1.66 MB或更大時,發生錯誤說「文件大小超過了長度」。如何使系統儘可能接受大文件大小。該文件保存在數據庫中,列類型爲varbinary(max)。不知道是什麼導致了這個錯誤!文件大小超過長度

的代碼是:

if (FileUpload1.HasFile) 
{ 
    if (ext.Equals(".pdf")) 
    { 
     Stream fs = FileUpload1.PostedFile.InputStream; 
     BinaryReader br = new BinaryReader(fs); 
     Byte[] bytes = br.ReadBytes((Int32)fs.Length); 

     string classNmae = ddClass.Text.Split('~')[0] + ddClass.Text.Split('1'); 
     com.Parameters.Clear(); 
     com.CommandText = "UPDATE [Marking] SET [fileName][email protected], [fileType][email protected], [type][email protected],[submissionDate][email protected], [filePath][email protected] where [class_id][email protected] AND [module_id][email protected] AND [student_id]= '" + Session["id"].ToString() + "'"; 
     com.Parameters.Add("@cid", SqlDbType.VarChar).Value = ddClass.Text.Split('~')[0]; 
     com.Parameters.Add("@mid", SqlDbType.VarChar).Value = ddClass.Text.Split('~')[1]; 
     com.Parameters.Add("@fileName", SqlDbType.VarChar).Value = filename; 
     com.Parameters.Add("@fileType", SqlDbType.VarChar).Value = "application/pdf"; 
     com.Parameters.Add("@typ", SqlDbType.VarChar).Value = txtType.Text; 
     com.Parameters.Add("@sd", SqlDbType.VarChar).Value = DateTime.Now; 
     com.Parameters.Add("@fp", SqlDbType.Binary).Value = bytes; 

     com.ExecuteNonQuery(); 
+3

爲什麼你不使用參數化SQL作爲學生ID?使用* everything *的參數。 (這與問題無關,但無論如何你都應該這樣做。) – 2014-12-27 19:54:55

+0

檢查與最大請求大小相關的IIS站點的配置 - http://ajaxuploader.com/large-file-upload-iis-asp- net.htm,**也是Jon Skeet所說的!** – 2014-12-27 19:55:36

+1

還要記住,一個數據庫不是文件服務器 – 2014-12-27 19:56:08

回答

3

在你的web.config文件:

<configuration> 
    <system.web> 
     <httpRuntime maxRequestLength="16384" /> 
    </system.web> 
</configuration> 

的值是KB。在這種情況下等於16MB。

+0

我試圖使用此代碼,但它導致了一個錯誤「HTTP錯誤500.19 - 內部服務器錯誤」 – 2014-12-27 20:22:09

+0

所以你爲什麼接受這個答案? – 2014-12-28 12:32:59

相關問題