开发者

How to put large text data (~20mb) into sql cs 3.5 database?

开发者 https://www.devze.com 2022-12-27 14:18 出处:网络
I am using following query to insert some large text data : internal static string InsertStorageItem =

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


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.


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
  3. FolderName

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


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. I guess that would help you.

Cheers AK

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号