[英]How to put large text data (~20mb) into sql cs 3.5 database?
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? 现在我的问题是我应该如何将如此大的数据插入sqlce db?
Regards, 问候,
Anindya Chatterjee 安妮迪娅(Anindya Chatterjee)
Have you read the docs for ntext data type? 您是否阅读过有关ntext数据类型的文档?
Variable-length Unicode data with a maximum length of 230 - 1 (1,073,741,823) characters. 可变长度Unicode数据,最大长度为230-1(1,073,741,823)个字符。 Storage size, in bytes, is two times the number of characters entered 存储大小(以字节为单位)是输入字符数的两倍
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. 如果是这样,那么您不走运-您需要一种数据类型,该数据类型可以存储比ntext更多的数据。 My suggestion: varbinary(MAX) or Image. 我的建议是:varbinary(MAX)或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. 也许对外部文件的引用(链接-路径)将是一个更好的解决方案。
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. 因此,首先使用StorageData = NULL或一个小文本对其进行测试。
I'd suggest specifying the length of the field when creating the parameter: 我建议在创建参数时指定字段的长度:
var paramData = command.Parameters.Add("@StorageData", System.Data.SqlDbType.NText, /* column length here */);
paramData.Value = content;
I if you can change the type of StorageData
from ntext
to image
and write your content as Binary. 我是否可以将StorageData
的类型从ntext
更改为image
并将内容写为Binary。 I guess that would help you. 我想那对您有帮助。
Cheers AK 干杯AK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.