当我尝试在 Sql 服务器中保存视频时,我遇到以下错误: 请求过滤模块,用于拒绝超过请求内容长度的请求。
//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))
{
//// ????
}
}
}
//我在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);
最佳答案
与其尝试将视频数据编码为字节并将其存储在数据库中,不如将视频存储在磁盘上并将视频的路径存储在数据库中。因此,您可以进行更高效的设计,而不是让数据库变得臃肿。
关于c# - 如何使用C#在Sql-Server中插入视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55400744/