c# - SqlException.Message returns wrong order of messages -


i making database update mechanism supposed run sql scripts , insert results update log table.

i using c# run scripts , dynamically set sql message that's supposed inserted update log table.

if there error in script, catching , using sqlexception.message write message.

if (exception != null) {     sqlmessage += exception.message + environment.newline;     break; } 

my script looks (numbers , arrow not in script):

1.   use [database]       if (exists (select * information_schema.tables                   table_schema = 'dbo'                   ,  table_name = 'users'))      begin          print('table exists - proceeding insert');      end      else      begin          -- creating table          create table [dbo].[users](              [userid] [int] not null,              [userfullname] [nvarchar](100) not null,              [username] [nvarchar](100) not null,              [usershortname] [nvarchar](50) not null,              [userlogin] [varchar](50) not null          ) 2.       print 'created table'      end  3.-> if(exists(select * [users_error] userid = 1 ))      begin          print('user exists - nothing insert');      end      else      begin          -- inserting user          insert [dbo].[users]                ([userid]                ,[userfullname]                ,[username]                ,[usershortname]                ,[userlogin])          values                (1,'system administrator','admin','sa',    'sa')          print 'inserted user'      end 

for testing purposed changed "users" "users_error" throw error (line arrow).

i expecting following log (numbers correspond numbers in script):

----- started 2.sql ----- 1. changed database context 'database'. 2. created table 3. invalid object name 'users_error'.      ----- finished 2.sql ----- 

instead, got following log:

----- started 2.sql ----- 3. invalid object name 'users_error'. 1. changed database context 'database'. 2. created table ----- finished 2.sql ----- 

is there way normal order? quite annoying debug script log messages on place.

thanks!

invalid object name 'users_error' compilation error. other 2 execution messages. compilation of batch occurs before execution. more details, read understanding how sql server executes query.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -