Note that there are some explanatory texts on larger screens.

plurals
  1. POupload large video to databsse in asp.ngj
    text
    copied!<p>I searched about how I could save and store large video size greater than 4MB into database using asp.net . I tried a many codes. also I used :</p> <pre><code>&lt;httpRuntime maxRequestLength="102400" executionTimeout="3600" /&gt; &lt;security &gt; &lt;requestFiltering&gt; &lt;requestLimits maxAllowedContentLength="1024000000" /&gt; &lt;/requestFiltering&gt; &lt;/security&gt; </code></pre> <p>It is not work. It show me message :</p> <p>timeout expired. the timeout period elapsed prior to completion of the operation or the server is not responding</p> <p>so far, I changed data column into varbinary(MAX) but I cann't store large file with size 100MB to up.</p> <p>My code </p> <pre><code> protected void Button1_Click(object sender, EventArgs e) { // Read the file and convert it to Byte Array string filePath = FileUpload1.PostedFile.FileName; string filename = Path.GetFileName(filePath); string ext = Path.GetExtension(filename); string contenttype = String.Empty; if (ext == ".jpg" || ext == ".gif" || ext == ".png" || ext == ".bmp " || ext == " .jpeg") { Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); //insert the file into database string strQuery = "insert into Image(Img_Title, Img_Extension, Img_Data, Course_code, Course_num, Img_Description, Keyword , Date)" + " values (@Img_Title, @Img_Extension, @Img_Data, @Course_code, @Course_num, @Img_Description, @Keyword , @Date)"; SqlCommand cmd = new SqlCommand(strQuery); cmd.Parameters.Add("@Img_Title", SqlDbType.VarChar).Value = filename; cmd.Parameters.Add("@Img_Extension", SqlDbType.VarChar).Value = ext; cmd.Parameters.Add("@Img_Data", SqlDbType.Binary).Value = bytes; cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Now; cmd.Parameters.Add("@Course_code", Course_code.SelectedItem.Text); cmd.Parameters.Add("@Course_num", Course_num.SelectedItem.Text); cmd.Parameters.Add("@Img_Description", Description.Text); cmd.Parameters.Add("@Keyword", keywords.Text); InsertUpdateData(cmd); Label2.ForeColor = System.Drawing.Color.Green; Label2.Text = "تم رفع الملف بنجاح"; } else if (ext == ".avi" || ext == ".wmv" || ext == ".wma" || ext == ".wma " || ext == " .wma" || ext == ".rmvb" || ext == ".mp4" || ext == ".3gp " || ext == " .mkv" || ext == ".flv") { Byte[] buffer; Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); HttpPostedFile file = FileUpload1.PostedFile;//retrieve the HttpPostedFile object buffer = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length); int bytesReaded = file.InputStream.Read(buffer, 0, FileUpload1.PostedFile.ContentLength); if (bytesReaded &gt; 0) { // FileUpload1.SaveAs(Server.MapPath("../WebSite41/Videos/" + filenam)); //insert the file into database string strQuery = "insert into [Video File](V_Title, V_Extension, Data, Course_code, Course_num, V_Description, Keyword,videoSize)" + " values (@V_Title, @V_Extension, @Data, @Course_code, @Course_num, @V_Description, @Keyword ,@videoSize)"; SqlCommand cmd = new SqlCommand(strQuery); // cmd.CommandTimeout = 90; cmd.Parameters.Add("@V_Title", SqlDbType.VarChar).Value = FileUpload1.FileName; cmd.Parameters.Add("@V_Extension", SqlDbType.VarChar).Value = ext; //cmd.Parameters.AddWithValue("@Data", buffer); cmd.Parameters.AddWithValue("@Data", "../foldername/Videos/" + filename); cmd.Parameters.Add("@Course_code", Course_code.SelectedItem.Text); cmd.Parameters.Add("@Course_num", Course_num.SelectedItem.Text); cmd.Parameters.Add("@V_Description", Description.Text); cmd.Parameters.Add("@Keyword", keywords.Text); cmd.Parameters.Add("@videoSize", SqlDbType.BigInt).Value = file.ContentLength; InsertUpdateData(cmd); Label2.ForeColor = System.Drawing.Color.Green; Label2.Text = "تم رفع الملف بنجاح"; } } else if (ext == ".doc" || ext == ".docx" || ext == ".docm" || ext == ".dotm" || ext == ".dotx" || ext == ".xls " || ext == " .xlsx" || ext == " .xlsb" || ext == " .xlam" || ext == ".ppt" || ext == ".pptx" || ext == ".pptm" || ext == ".potx" || ext == ".ppam" || ext == ".ppsx" || ext == ".ppsm" || ext == ".sldx" || ext == ".sldm" || ext == ".thmx" || ext == ".pdf" || ext == ".txt ") { Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); //insert the file into database string strQuery = "insert into [Text File](T_Title, T_Extension, T_Data, Course_code, Course_num, T_Description, T_Keyword,Date)" + " values (@T_Title, @T_Extension, @T_Data, @Course_code, @Course_num, @T_Description, @T_Keyword,@Date)"; SqlCommand cmd = new SqlCommand(strQuery); cmd.Parameters.Add("@T_Title", SqlDbType.VarChar).Value = filename; cmd.Parameters.Add("@T_Extension", SqlDbType.VarChar).Value = ext; cmd.Parameters.Add("@T_Data", SqlDbType.Binary).Value = bytes; cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Now; cmd.Parameters.Add("@Course_code", Course_code.SelectedItem.Text); cmd.Parameters.Add("@Course_num", Course_num.SelectedItem.Text); cmd.Parameters.Add("@T_Description", Description.Text); cmd.Parameters.Add("@T_Keyword", keywords.Text); InsertUpdateData(cmd); Label2.ForeColor = System.Drawing.Color.Green; Label2.Text = "تم رفع الملف بنجاح"; } else if (ext.ToLower() == ".html" || ext.ToLower() == ".htm") { Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); //insert the file into database string strQuery = "insert into [HTML File](H_Title, H_Extension, H_Data, Course_code, Course_num, H_Description, H_Keyword,Date)" + " values (@H_Title, @H_Extension, @H_Data, @Course_code, @Course_num, @H_Description, @H_Keyword ,@Date)"; SqlCommand cmd = new SqlCommand(strQuery); cmd.Parameters.Add("@H_Title", SqlDbType.VarChar).Value = filename; cmd.Parameters.Add("@H_Extension", SqlDbType.VarChar).Value = ext; cmd.Parameters.Add("@H_Data", SqlDbType.Binary).Value = bytes; cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Now; cmd.Parameters.Add("@Course_code", Course_code.SelectedItem.Text); cmd.Parameters.Add("@Course_num", Course_num.SelectedItem.Text); cmd.Parameters.Add("@H_Description", Description.Text); cmd.Parameters.Add("@H_Keyword", keywords.Text); InsertUpdateData(cmd); Label2.ForeColor = System.Drawing.Color.Green; Label2.Text = "تم رفع الملف بنجاح"; } else { Label2.ForeColor = System.Drawing.Color.Red; Label2.Text = "Error" + " Upload Image/Text formats"; } } private Boolean InsertUpdateData(SqlCommand cmd) { String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(strConnString); cmd.CommandType = CommandType.Text; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); return true; } catch (Exception ex) { Response.Write(ex.Message); return false; } finally { con.Close(); con.Dispose(); } } </code></pre> <p>Thanks ...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload