gpt4 book ai didi

c# - 如何将大文本数据(~20mb)放入 sql cs 3.5 数据库?

转载 作者:搜寻专家 更新时间:2023-10-30 21:48:28 25 4
gpt4 key购买 nike

我正在使用以下查询来插入一些大文本数据:

internal static string InsertStorageItem =
"insert into Storage(FolderName, MessageId, MessageDate, StorageData) values ('{0}', '{1}', '{2}', @StorageData)";

我用来执行这个查询的代码如下:

string content = "very very large data";
string query = string.Format(InsertStorageItem, "Inbox", "AXOGTRR1445/DSDS587444WEE", "4/19/2010 11:11:03 AM");
var command = new SqlCeCommand(query, _sqlConnection);
var paramData = command.Parameters.Add("@StorageData", System.Data.SqlDbType.NText);
paramData.Value = content;
paramData.SourceColumn = "StorageData";
command.ExecuteNonQuery();

但在最后一行我收到以下错误:

 System.Data.SqlServerCe.SqlCeException was unhandled by user codeMessage=The data was truncated while converting from one data type to another. [ Name of function(if known) =  ]Source=SQL Server Compact ADO.NET Data ProviderHResult=-2147467259NativeError=25920StackTrace:       at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)       at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)       at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)       at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()       at Chithi.Client.Exchange.ExchangeClient.SaveItem(Item item, Folder parentFolder)       at Chithi.Client.Exchange.ExchangeClient.DownloadNewMails(Folder folder)       at Chithi.Client.Exchange.ExchangeClient.SynchronizeParentChildFolder(WellKnownFolder wellknownFolder, Folder parentFolder)       at Chithi.Client.Exchange.ExchangeClient.SynchronizeFolders()       at Chithi.Client.Exchange.ExchangeClient.WorkerThreadDoWork(Object sender, DoWorkEventArgs e)       at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)       at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)InnerException: 

现在我的问题是我应该如何将如此大的数据插入到 sqlce 数据库中?

问候,

阿宁迪亚·查特吉

http://abstractclass.org

最佳答案

您是否阅读过 ntext 数据类型的文档?

Variable-length Unicode data with a maximum length of 230 - 1 (1,073,741,823) characters. Storage size, in bytes, is two times the number of characters entered

您的超大内容的大小是否大于最大值?如果是这样,你就不走运了——你需要一种比 ntext 可以存储更多数据的数据类型。我的建议:varbinary(MAX) 或 Image。

关于c# - 如何将大文本数据(~20mb)放入 sql cs 3.5 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2665905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com