C# / Sql Server 2008 INSERT int value grows automatically to 1000000 -
i had strange problem occured 1 time in sql server 2008.
i work in .net web application (c#) , use sqlcommand access database , execute queries. process following:
i have view me maximum number existing in specific table:
select max(number) maxnumber mytable
i maxnumber in variable and, variable, execute insert in mytable maxnumber + 1. that, have maximum number logged in mytable
it worked since 1 time, week ago, when, suddenly, saw maxnumber passed 134200 1000000 !
i investigate code , there no way reason of behavior. inspected logs of web server, no logs of bad insert throwned.
i looked logs of sql server i've found no logs of error...
what suspicious number passed "common" number (134200) "specific" number (1000000). why 1000000 ? why not 984216 or 1000256 ?
is there experienced same problem ?
thanks help.
edit - 2014-12-23:
i analyzed further problem , seems occurred when restored backup in preprod environment.
i explain: have preprod server have sql server instance (preprod) , have prod server have sql server instance (prod), backed every day, on same server.
when want test effective datas, restore prod backups on preprod databases:
restore database preprod disk = '\\prod\backup\sql\prod.bak' move 'prod' 'e:\bases\data\preprod.mdf', move 'prod_log' 'e:\bases\data\preprod.ldf', replace
the problem occurred same day restored backup. "1000000 row" appeared @ same moment of restore, on prod database. there possibility it's linked ? prod server overwhelmed restore command executed preprod server, , it, eventually, crashed insert request occurred @ same moment ?
thanks advices
the thing can think maybe getting maxvalue executescalar method without casting result proper datatype
var max= cmd.executescalar();
and
max= max+1;
otherwise saw version of sqlserver may receive incorrect values when using scope_identity()
, @@identity
refer here bug fix, should update sql server 2008 r2 service pack 1
Comments
Post a Comment