본문 바로가기

DB

(54)
[Z.EntityFramework.extention][bulkinsert] c# example using (var context = new KSKEntities()) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; context.Database.Connection.Open(); using (var ts = new TransactionScope()) { try { context.BulkInsert(SampleList); context.BulkSaveChanges(); ts.Complete(); Console.WriteLine("bulk insert : OK"); } catch (Exception ex) { ts.Dispose(); Console.Wri..
[Z.EntityFramework.extention][BulkInsert] 열 ID %1에 대해 bcp 클라이언트에서 잘못된 열 길이를 받았습니다. 열 ID %1에 대해 bcp 클라이언트에서 잘못된 열 길이를 받았습니다. bulkinsert 에 필요한 데이터 구문이 잘려서 이후 데이터가 들어가지 않고 예외를 발생합니다. 해결책 1. garbage collector C# 의 경우에는 GC.Collect() 로 garbage collector 를 실행해주면 어느정도 해결이 됩니다. 확실한 해결책은 아니란 얘기~. garbage collector 의 실행부분은 반복문 하단이나 단위 메소드의 실행 끝에 실행해줍니다. 적절히 garbage 가 clear 되었는지는 visual studio > analyze > performance and Diagnostics 에서 모니터링 할 수 있는데 Force GC 로 강제로 실행 할 수 있는 버튼도 지원해서 임의로 cl..
[Visual Studio][Entity Framework 6] How to delete auto-generated Comments ooo.edmx > ooo.Context.tt line 21 ~ 28 //------------------------------------------------------------------------------ // // // // // // //------------------------------------------------------------------------------ ooo.edmx > ooo.tt line 228 ~ 235 //------------------------------------------------------------------------------ // // // // // // //---------------------------------------------..
[function] 문자열에서 숫자만 뽑아내기 CREATE FUNCTION fn_GetNumeric (@strAlphaNumeric VARCHAR(256)) returns VARCHAR(256) AS BEGIN DECLARE @intAlpha INT SET @intAlpha = Patindex('%[^0-9]%', @strAlphaNumeric) BEGIN WHILE @intAlpha > 0 BEGIN SET @strAlphaNumeric = Stuff(@strAlphaNumeric, @intAlpha, 1, '') SET @intAlpha = Patindex('%[^0-9]%', @strAlphaNumeric) END END RETURN Isnull(@strAlphaNumeric, 0) END 예) SELECT dbo.fn_GetNumeric('1..
[function] 숫자에 억,만 단위 붙이기 CREATE FUNCTION [dbo].[fn_MoneyToKor]( @price FLOAT)RETURNS NVARCHAR(500)ASBEGINDECLARE @salePrice FLOATDECLARE @deposit FLOATDECLARE @monthlyRent FLOATDECLARE @tempMoney1 FLOATDECLARE @tempMoney2 FLOATDECLARE @tempMoney NVARCHAR(500) = '' SET @deposit = @price;SET @monthlyRent = 100; SET @tempMoney1 = FLOOR(@deposit / 100000000)SET @tempMoney2 = FLOOR((@deposit - (@tempMoney1 * 100000000)) / 10..
[function] 구분자가 있는 문자열 테이블로 만들기 CREATE FUNCTION [dbo].[fn_Split]( @pSource NVARCHAR(MAX), @pSeparator VARCHAR(1))RETURNS @TAB_RETURN TABLE( ItemIndex INT, ItemValue NVARCHAR(1000))ASBEGIN DECLARE @buffer VARCHAR(MAX); DECLARE @item NVARCHAR(MAX); DECLARE @tmp INT; DECLARE @index INT; SET @index = 1; WHILE LEN(@pSource) > 0 BEGIN SET @tmp = CHARINDEX(@pSeparator, @pSource); IF @tmp > 0 BEGIN SET @item = SUBSTRING(@pSource, 1, @..
error CS1061: 'int' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) error CS1061: 'int' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?) 1. 원인 entoty framework 에 매핑 한 stored procedure 가 model 을 제대로 생성 할 수 없을때 발생하는 오류입니다.1-1. 예sp 내부에 #TEMP 테이블 join이나 select 가 있으며 list 로 가져올 컬럼을 매핑 할 수 없을 때 발생합니다. 즉, var onbidObjectList =..
[mssql] paging limit offset DECLARE @page INT = 1DECLARE @offset INT = 5 ;WITH TempTable AS( SELECT ROW_NUMBER() OVER (ORDER BY 정렬컬럼 ) AS RowNum , * FROM Table WITH(NOLOCK) WHERE 조건)SELECT *FROM TempTableWHERE RowNum > ( CASE WHEN @page > 1 THEN ( @page - 1 ) * @offset ELSE 0 END ) AND RowNum