当文件大小为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