2014-12-27 93 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

相关问题