This is a migrated thread and some comments may be shown as answers.
Column values truncated during the batch insert
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dj Prpa
Top achievements
Rank 1
Dj Prpa asked on 05 Mar 2012, 09:59 PM
I am using MS SQL 2008 R2 database. I am doing a batch insert of records. However, most of data values were truncated during the insert. It looks like that OA creates a SQL statement based on the length of data (from the first record in the batch) and not based on the length of the field specified in database. 

Here is the code taken from the OA context class:

[Column("addressto", OpenAccessType = OpenAccessType.Character, IsNullable = true, Length = 100, Scale = 0, SqlType = "char")]

Here is the SQL statement generated by OA for the first record in the batch (taken form SQL Profiler). 
declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@p0 nvarchar(20),@p1 nvarchar(22),@p2 nvarchar(16),@p3 datetime,@p4 int,@p5 nvarchar(24),@p6 nvarchar(10),@p7 nvarchar(9),@p8 nvarchar(61),@p9 nvarchar(17)',N'INSERT INTO [ETM_Log] ([addressfrom], [addressto], [etm_span_recid], [emaildate], [issuccess], [namefrom], [nameto], [student_id], [subject], [defuserid]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9)

Here is the SQL statement for the second record from the batch:
exec sp_execute 1,@p0=N'',@p1=N'',@p2=N'',@p3='2012-03-05 15:39:30.710',@p4=1,@p5=N'',@p6=N'',@p7=N'',@p8=N'',@p9=N''

Thank you for your help.

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 08 Mar 2012, 04:01 PM
Hi Zoran,

gotcha! This seems like a bug, and we are working on a fix. The problem can be worked-around when using a varchar or nvarchar type in that table too. It seems, that the SqlClient does not really prepare statements when they include nvarchar/varchar columns, and the bug is bound to prepared execution with a wrong size of the parameter.
I've updated your Telerik Points, thanks for reporting this issue.

Kind regards,
Thomas
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Tags
General Discussions
Asked by
Dj Prpa
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or