简体   繁体   English

如何将大文本数据(〜20mb)放入sql cs 3.5数据库中?

[英]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)

http://abstractclass.org http://abstractclass.org

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: 按照可能性:

  1. MessageDate 留言日期
  2. MessageId MessageId
  3. FolderName 文件夹名称

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.

相关问题 'OutOfMemoryException'读取20mb XLSX文件 - 'OutOfMemoryException' reading 20mb XLSX file 为什么WCF服务在传输大量文本数据(大约20 MB)时停止并发 - Why WCF Service stops concurrency while transferring large amount of text data (around 20 MB) Blazor 服务器 - websocket 连接失败 1006 - PDF 查看器(文件大小为 13mb 到 20mb) - Blazor Server - websocket connection to failed 1006 - PDF Viewer (with file size 13mb to 20mb) 即使在DropZone中将maxFilesize设置为500,也无法加载文件大小超过20MB的文件 - Unable to load file with file size more than 20MB even though maxFilesize is set to 500 in DropZone VS 2008 - SQL CE 3.5数据库,数据集错误 - MSDataSetGenerator不生成designer.cs代码 - VS 2008 - SQL CE 3.5 database, Dataset Error - MSDataSetGenerator not generate designer.cs code 将文本文件(500 MB)数据导入SQL Server - import text file(500 MB) data into SQL Server 如何将20个100mb CSV文件批量插入SQL Server - How to bulk insert 20 100mb CSV files into SQL Server 将大文本文件导入sql数据库 - Importing large text file into sql database 如何将显示的sql数据加载到wpf可滚动列表视图中? 大集合(20k +)没有遇到内存问题? - how to load displayed sql data into wpf scrollable list view? large collection (20k+) without running into memory problems? 将大量数据复制到SQL CE数据库中 - Copying large amounts of data into a SQL CE database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM