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

发布于 2024-08-29 12:40:45 字数 2189 浏览 5 评论 0原文

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

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

http://abstractclass.org

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

http://abstractclass.org

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

剩一世无双 2024-09-05 12:40:45

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

可变长度 Unicode 数据
最大长度 230 - 1
(1,073,741,823) 个字符。贮存
大小(以字节为单位)是两倍
输入的字符数

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

Have you read the docs for ntext data type?

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

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.

不必在意 2024-09-05 12:40:45

也许您应该考虑一下为什么必须将如此大量的文本放入数据库中。也许对外部文件的引用(链接-路径)将是更好的解决方案。

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.

埋葬我深情 2024-09-05 12:40:45

您列出的代码应该可以工作。你先检查过你的基地吗?

我认为可能是其他列之一引发了异常。按照可能性的顺序:

  1. MessageDate
  2. MessageId
  3. FolderName

因此,首先使用 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:

  1. MessageDate
  2. MessageId
  3. FolderName

So, first test it with StorageData=NULL or a small text.

瑶笙 2024-09-05 12:40:45

我建议在创建参数时指定字段的长度:

var paramData = command.Parameters.Add("@StorageData", System.Data.SqlDbType.NText, /* column length here */);
paramData.Value = content;

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;
傲世九天 2024-09-05 12:40:45

我是否可以将 StorageData 的类型从 ntext 更改为 image 并将内容写入为二进制。我想这会对你有帮助。

干杯
AK

I if you can change the type of StorageData from ntext to image and write your content as Binary. I guess that would help you.

Cheers
AK

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文