簡體   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