sql - What is the execute command to use here -


protected void page_load(object sender, eventargs e)     {         string sqlconnectionstring = @"data source=phriz-webapp01;initial catalog=pftracking;integrated security=true";         string script = "if not exists(select * sys.servers name=n'cnctc-web01')begin exec sp_addlinkedserver @server='cnctc-web01'exec sp_addlinkedsrvlogin 'cnctc-web01','false',null,'svc_phils','apple@6' end insert [pftracking].[dbo].[temptable] select c.[pf_id],a.[requestdate],c.[pf_carrierused],b.[pieceprice] * b.[partquantity] [amount] ,c.[pf_type],c.[pf_ressupplier] ,c.[pf_rescustomer],c.[pf_trailernum] ,b.[partdesc]  ,c.[pf_chargeback]  ,c.[pf_chargetoplant] [cnctc-web01].[nop_pr].[dbo].[requests] join [cnctc-web01].[nop_pr].[dbo].[parts] b on a.[requestid] = b.[requestid] join [phriz-webapp01].[pftracking].[dbo].[tbl_pfexcel] c on  b.[partnumber] '%'+c.pf_id+'%'where a.[entityname] '%pta' , a.[requestdate] between '2015-04-20 00:00:00.000' , getdate() ";         sqlconnection conn = new sqlconnection(sqlconnectionstring);         conn.open();         sqlcommand comm = new sqlcommand(script, conn);         comm.executenonquery();         conn.close();     } 

i wanted execute command server each time page accessed db loads.

comm.executenonquery() 

additional :

an exception of type 'system.data.sqlclient.sqlexception' occurred in system.data.dll not handled in user code

additional information: timeout expired. timeout period elapsed prior completion of operation or server not responding.`

line 21:             conn.open(); line 22:             sqlcommand comm = new sqlcommand(script, conn); line 23:             **comm.executenonquery();** line 24:             conn.close(); line 25:         } 

that's error gives .. ?

have @ , tell me if works - i've added try catch check if command timing out.

just few tips:

i use try catch because it'll tell need know , why code isn't working.

also use using statement because using statements ensure non-managed resources disposed, cannot handle exceptions.

also,sqlcommand implements idisposable, i'd suggest putting in using block well.

protected void page_load(object sender, eventargs e) {    using (sqlconnection conn = new sqlconnection("data source=phriz-webapp01;initial catalog=pftracking;integrated security=true";))    {       conn.open();       string script = "if not exists(select * sys.servers name=n'cnctc-web01')begin exec sp_addlinkedserver @server='cnctc-web01'exec sp_addlinkedsrvlogin 'cnctc-web01','false',null,'svc_phils','apple@6' end insert [pftracking].[dbo].[temptable] select c.[pf_id],a.[requestdate],c.[pf_carrierused],b.[pieceprice] * b.[partquantity] [amount] ,c.[pf_type],c.[pf_ressupplier] ,c.[pf_rescustomer],c.[pf_trailernum] ,b.[partdesc]  ,c.[pf_chargeback]  ,c.[pf_chargetoplant] [cnctc-web01].[nop_pr].[dbo].[requests] join [cnctc-web01].[nop_pr].[dbo].[parts] b on a.[requestid] = b.[requestid] join [phriz-webapp01].[pftracking].[dbo].[tbl_pfexcel] c on  b.[partnumber] '%'+c.pf_id+'%'where a.[entityname] '%pta' , a.[requestdate] between '2015-04-20 00:00:00.000' , getdate() ";        using (var comm = new sqlcommand(script, conn))       {         // setting command timeout 2 minutes         comm.commandtimeout = 120;         try          {            command.executenonquery();         }         catch (sqlexception e)          {            console.writeline("got expected sqlexception due command timeout ");            console.writeline(e);         }       }       conn.close();    } } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -