如何将大文件插入VARBINARY(MAX) [英] How to insert big file into VARBINARY(MAX)
本文介绍了如何将大文件插入VARBINARY(MAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想将3MB的文件插入数据库.
FaxMessage.FaxFile是一个byte []-3MB文件.
我使用存储过程,如下所示:
Hi, I want to insert to database 3MB file.
faxMessage.FaxFile is a byte[] - 3MB file.
I use stored procedures, like below:
using (SqlCommand sc = new SqlCommand("Myproc", sqlConnection))
{
sc.CommandType = CommandType.StoredProcedure;
sc.CommandTimeout = 100;
sc.Transaction = transaction;
sc.Parameters.Add(new SqlParameter("@inFaxFile", SqlDbType.VarBinary, faxMessage.FaxFile.Length));
sc.Parameters["@inFaxFile"].Value = faxMessage.FaxFile;
using (sc.ExecuteReader())
{
}
}
我应该更改SQL Server配置中的某些内容吗?它是简单的VARCHAR(MAX)列.
我知道,也许这是菜鸟问题,但是请帮我.
更新:
还是我需要在存储过程中更改某项?这是代码:
Should I change sth in SQL Server configuration ? It is simple VARCHAR(MAX) column.
I know, that maybe this is rookie question, but pleas help me.
UPDATE:
Or maybe I need to change sth in stored procedure? Here is the code:
BEGIN TRANSACTION
BEGIN
BEGIN TRY
INSERT INTO [mgdb].[dbo].[Message]
([NumberFrom]
,[FaxFile])
VALUES
(@inNumberFrom
,@inFaxFile)
SET @outId = SCOPE_IDENTITY()
COMMIT
END TRY
BEGIN CATCH
SET @outId = -1
ROLLBACK
END CATCH
END
推荐答案
使用Image
数据类型存储文件.更改表,SP和C#代码中的数据类型,代码将像超级按钮一样工作.
Use Image
datatype for storing files. Change the datatype in your Table, your SP and your C# code and your code will work like a charm.
这篇关于如何将大文件插入VARBINARY(MAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文