2

When I try to save a video in Sql server, i'm facing to this kind of error bellow: The request filtering module is configured to deny a request that exceeds the request content length.

//Converting a file Uploaded in byte before inserting it in DB.

using (BinaryReader br = new BinaryReader(fs))
{
   byte[] bytes = br.ReadBytes((Int32)fs.Length);
   string constr = (@"Data Source=(localdb)\MSSQLLocalDB;....");               

   using (SqlConnection con = new SqlConnection(constr))
   {
      string query = "insert into tblFiles values (@Name, @ContentType, @Data)";

      using (SqlCommand cmd = new SqlCommand(query))
      {
         //// ????
      }
   }
}

//The Kind of table i'm Using in Sql_Server

CREATE TABLE tblFiles(Id int IDENTITY PRIMARY KEY,Name 
           VARCHAR(100) NOT NULL,
            ContentType NVARCHAR(4000)NOT NULL, Data VARBINARY(MAX)NOT 
              NULL);
IronAces
  • 1,857
  • 1
  • 27
  • 36
Joseph
  • 21
  • 1
  • 5
    I would urge you not to store videos directly in the database like this. Why not store them on disc and put the path and filename in the database? – Sean Lange Mar 28 '19 at 14:59
  • Or use [BLOB](https://learn.microsoft.com/En-us/sql/relational-databases/blob/binary-large-object-blob-data-sql-server?view=sql-server-2017) ? (But yeah, I would store the video on disc instead of DB) – Cid Mar 28 '19 at 15:00
  • 5
    if the problem is "The request filtering module is configured to deny a request that exceeds the request content length.", then ... the problem has nothing to do with the storage location (and in particular: is nothing to do with SQL Server, although I agree with @SeanLange that storing this in a database is a bad choice) - you'll get the same problem *where-ever* you store it - the problem is that it is *too big*, meaning: your web-server is configured to treat that as malicious. For good reason. It will be the same size no matter where/how you store it. – Marc Gravell Mar 28 '19 at 15:01
  • 1
    Possible duplicate of [IIS7 - The request filtering module is configured to deny a request that exceeds the request content length](https://stackoverflow.com/questions/10871881/iis7-the-request-filtering-module-is-configured-to-deny-a-request-that-exceeds) – NineBerry Mar 28 '19 at 15:11

2 Answers2

2

Rather then trying to codify the video data into bytes and store it in the database it would be better practice to store the video on your disk and store the path to the video in your database. Thus rather then bloating your database you have more efficient design.

Storing Images in DB - Yea or Nay?

Joey Phillips
  • 1,543
  • 2
  • 14
  • 22
1

just add it with parameters like any other datatypes:

cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = name;
cmd.Parameters.Add("@Data", SqlDbType.VarBinary).Value = bytes;
cmd.Parameters.Add("@ContentType", SqlDbType.NVarChar).Value = contentType;
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171