如何将大文本数据(~20mb)放入sql cs 3.5数据库?
我正在使用以下查询插入一些大文本数据:
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 code Message=The data was truncated while converting from one data type to another. [ Name of function(if known) = ] Source=SQL Server Compact ADO.NET Data Provider HResult=-2147467259 NativeError=25920 StackTrace: 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数据库?
问候,
Anindya Chatterjee
I am using following query to insert some large text data :
internal static string InsertStorageItem =
"insert into Storage(FolderName, MessageId, MessageDate, StorageData) values ('{0}', '{1}', '{2}', @StorageData)";
and the code I am using to execute this query is as follows :
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();
But at the last line I am getting this following error :
System.Data.SqlServerCe.SqlCeException was unhandled by user code Message=The data was truncated while converting from one data type to another. [ Name of function(if known) = ] Source=SQL Server Compact ADO.NET Data Provider HResult=-2147467259 NativeError=25920 StackTrace: 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:
Now my question is how am I supposed to insert such large data to sqlce db?
Regards,
Anindya Chatterjee
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您阅读过 ntext 数据类型的文档吗?
您的内容非常大,其大小是否大于最大值?如果是这样,那么你就不走运了——你需要一种可以存储比 ntext 更多数据的数据类型。我的建议:varbinary(MAX) 或 Image。
Have you read the docs for ntext data type?
Is your very large content greater in size than the maximum? If so you're out of luck - you need a data type which can store more data than ntext. My suggestion: varbinary(MAX) or Image.
也许您应该考虑一下为什么必须将如此大量的文本放入数据库中。也许对外部文件的引用(链接-路径)将是更好的解决方案。
Maybe you should think about why do you have to put such large amounts of text into a database. Maybe a reference (link - path) to an external file would be a better solution.
您列出的代码应该可以工作。你先检查过你的基地吗?
我认为可能是其他列之一引发了异常。按照可能性的顺序:
因此,首先使用 StorageData=NULL 或小文本对其进行测试。
The code you listed ought to work. Have you checked your bases first?
I'm thinking it could be one of the other columns that throws the exception. In order of likelihood:
So, first test it with StorageData=NULL or a small text.
我建议在创建参数时指定字段的长度:
I'd suggest specifying the length of the field when creating the parameter:
我是否可以将
StorageData
的类型从ntext
更改为image
并将内容写入为二进制。我想这会对你有帮助。干杯
AK
I if you can change the type of
StorageData
fromntext
toimage
and write your content as Binary. I guess that would help you.Cheers
AK