本文介绍了通过asp.net将视频上传到sql server的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在处理我的项目并尝试将视频上传到数据库中。但它给了我错误.... protected void Button1_Click( object sender,EventArgs e) { if (FUVideo.PostedFile!= null ) { FileName = Path.GetFileName(FUVideo.PostedFile.FileName); // 将文件保存到磁盘 FUVideo.SaveAs( Server.MapPath( 〜/ Images / + FileName)); videosize = FUVideo.PostedFile.ContentLength; // 仅允许上载小于2,100,000字节(约2 MB)的文件。 // if(fileSize< 2100000) // 您的文件未上传,因为+ // 它超过了2 MB的大小限制。; videotype = FUVideo.PostedFile.ContentType; } 尝试 { db1.sqlcmd = new SqlCommand( uspAddVideos); 使用(SqlDataAdapter sda = new SqlDataAdapter()) { db1.sqlcmd.CommandType = CommandType.StoredProcedure; db1.sqlcmd.Parameters.AddWithValue( @ UserID,UserID); db1.sqlcmd.Parameters.AddWithValue( @ SubscripID,SubscripID); db1.sqlcmd.Parameters.AddWithValue( @ Title,Convert.ToString(TBVname .Text.Trim())); db1.sqlcmd.Parameters.AddWithValue( @ Details,Convert.ToString(TBVDesc .Text.Trim())); db1.sqlcmd.Parameters.AddWithValue( @ Category,Convert.ToString(TBCategory) .Text.Trim())); db1.sqlcmd.Parameters.AddWithValue( @ Name,FileName); db1.sqlcmd.Parameters.AddWithValue( @ Url, 〜/ Images / + FileName); // db1.sqlcmd.Parameters.AddWithValue(@ VideoSize,videosize); // db1.sqlcmd.Parameters.AddWithValue(@ VideoType,videotype); db1.sqlcmd.Parameters.Add( @ success,SqlDbType.Bit); db1.sqlcmd.Parameters [ @ success]。Direction = ParameterDirection.Output; db1.sqlcmd.Connection = db1.sqlcon; db1.sqlcon.Open(); db1.sqlcmd.ExecuteScalar(); success =( bool )db1.sqlcmd.Parameters [ @成功]值。 } } catch (例外情况) { Response.Write( ex.Message); } 最后 { 如果(成功== true ) { db1.sqlcon.Close(); } else {} db1.sqlcon.Close(); } } 创建 Proc uspAddVideos - @ VideoSize bigint,@ VideoType varchar(100), @success 位 out, @ Name nvarchar (max), @ Title nvarchar ( 100 ), @详细信息 varchar ( 250 ), @ Url varchar (max), @ Category varchar ( 50 ), @SubscripID int , @ UserID int AS BEGIN SET NOCOUNT ON ; BEGIN TRY INSERT INTO TblVideos(Title,Name,Url,Details,Category,PublishedOn,PublishedBy,SubcriptionId) VALUES ( @Title , @ Name , @ Url , @详细信息, @ Category ,GETDATE(), @ UserID , @ SubscripID ) 更新 TblSubscription SET MaxVideos = MaxVideos -1 WHERE SubscriptionId = @ SubscripID SET @ success = 1 结束尝试 BEGIN CATCH SET @成功 = 0 END CATCH END ,错误是..... 超出最大请求长度。 描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.Web.HttpException:超出最大请求长度。 解决方案 非常常见的问题。 http://stackoverflow.com/ questions / 3853767 / maximum-request-length-exceeded [ ^ ] I am working on my project and trying to upload videos into the data base. but it gives me the error....protected void Button1_Click(object sender, EventArgs e) { if (FUVideo.PostedFile != null) { FileName = Path.GetFileName(FUVideo.PostedFile.FileName); //Save files to disk FUVideo.SaveAs(Server.MapPath("~/Images/" + FileName)); videosize = FUVideo.PostedFile.ContentLength; // Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded. //if (fileSize < 2100000) //"Your file was not uploaded because " + // "it exceeds the 2 MB size limit."; videotype = FUVideo.PostedFile.ContentType; } try { db1.sqlcmd = new SqlCommand("uspAddVideos"); using (SqlDataAdapter sda = new SqlDataAdapter()) { db1.sqlcmd.CommandType = CommandType.StoredProcedure; db1.sqlcmd.Parameters.AddWithValue("@UserID", UserID); db1.sqlcmd.Parameters.AddWithValue("@SubscripID", SubscripID); db1.sqlcmd.Parameters.AddWithValue("@Title", Convert.ToString(TBVname.Text.Trim())); db1.sqlcmd.Parameters.AddWithValue("@Details", Convert.ToString(TBVDesc.Text.Trim())); db1.sqlcmd.Parameters.AddWithValue("@Category", Convert.ToString(TBCategory.Text.Trim())); db1.sqlcmd.Parameters.AddWithValue("@Name", FileName); db1.sqlcmd.Parameters.AddWithValue("@Url", "~/Images/" + FileName); //db1.sqlcmd.Parameters.AddWithValue("@VideoSize", videosize); //db1.sqlcmd.Parameters.AddWithValue("@VideoType", videotype); db1.sqlcmd.Parameters.Add("@success", SqlDbType.Bit); db1.sqlcmd.Parameters["@success"].Direction = ParameterDirection.Output; db1.sqlcmd.Connection = db1.sqlcon; db1.sqlcon.Open(); db1.sqlcmd.ExecuteScalar(); success = (bool)db1.sqlcmd.Parameters["@success"].Value; } } catch (Exception ex) { Response.Write(ex.Message); } finally { if (success == true) { db1.sqlcon.Close(); } else { } db1.sqlcon.Close(); } }Create Proc uspAddVideos--@VideoSize bigint,@VideoType varchar(100),@success bit out,@Name nvarchar(max),@Title nvarchar(100), @Details varchar(250),@Url varchar(max),@Category varchar(50), @SubscripID int,@UserID intASBEGINSET NOCOUNT ON;BEGIN TRYINSERT INTO TblVideos (Title,Name, Url, Details, Category, PublishedOn, PublishedBy,SubcriptionId) VALUES (@Title,@Name,@Url, @Details,@Category,GETDATE(),@UserID,@SubscripID)UPDATE TblSubscription SET MaxVideos = MaxVideos -1 WHERE SubscriptionId = @SubscripIDSET @success = 1END TRYBEGIN CATCHSET @success = 0END CATCHENDand the error is..... Maximum request length exceeded.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: Maximum request length exceeded. 解决方案 Pretty common problem.http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded[^] 这篇关于通过asp.net将视频上传到sql server的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 21:06