當文件大小爲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();
爲什麼你不使用參數化SQL作爲學生ID?使用* everything *的參數。 (這與問題無關,但無論如何你都應該這樣做。) – 2014-12-27 19:54:55
檢查與最大請求大小相關的IIS站點的配置 - http://ajaxuploader.com/large-file-upload-iis-asp- net.htm,**也是Jon Skeet所說的!** – 2014-12-27 19:55:36
還要記住,一個數據庫不是文件服務器 – 2014-12-27 19:56:08