繁体   English   中英

将.docx文件转换为二进制文件并插入varbinary(Max)时,如何解决“字符串或二进制数据将被截断”的问题?

[英]How to fix “String or binary data would be truncated” when convert .docx file to binary and insert into varbinary(Max)?

我使用FileStream使用Varbinaray(Max)将文件插入到列中。 这是我的示例代码:

byte[] dataBytes = File.ReadAllBytes(fileNameAndPath);
string insertCommand = string.Format(@" INSERT INTO [dbo].[ts000Attachments] ([Data]) values   (@Data)");
command.Parameters.Add("@Data",SqlDbType.VarBinary,-1).Value = dataBytes;

command.ExecuteNonQuery();

上面的代码使用.doc文件。 如何解决此问题。

根据以下链接,此问题全部与sql中的列大小有关:

堆栈溢出:

SQL Server字符串或二进制数据将被截断

SQL Server错误:字符串或二进制数据将被截断

微软:

字符串或二进制数据将被截断”和字段说明

代码项目:

字符串或二进制数据将被截断。 该语句已终止。

还要确保在表上激活了FileStream功能。 对我来说,我不知道为什么我的表没有使用FileStream功能创建。 因此,我放下了表并重新创建了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM