I am working on a web application asp.net and sql server 2kI have careated a stored procedure which returns a dataset to me. stored procedure works fine for me when records are less(less than 200 on remote server). But when records exceds from 200 it returns and Error"General network error. Check your network documentation"My stored procedure is as follows"
CREATE PROCEDURE sp_get_Shosp_for_scheduler_Editor_job_allocation@intPageNo numeric,@intpageSize numeric,@search as varchar(8000),@search1 as varchar(8000)AScreate table #tbl (id numeric identity,shop_id numeric, shop_title varchar(120), program_id numeric, program_name varchar(120), start_Date datetime, end_Date datetime, Target_Date datetime,location varchar(120),client varchar(120),client_id numeric,Scheduler varchar(120),Editor varchar(120),msp_employee_id numeric,location_id numeric,Shop_order numeric)Create table #tbl1 (id numeric identity,shop_id numeric, shop_title varchar(120), program_id numeric, program_name varchar(120), shop_start_Date datetime, shop_end_Date datetime, Target_Date datetime,location varchar(120),client_name varchar(120),client_id numeric,assigned_Scheduler varchar(120),assigned_Editor varchar(120),sche_msp_employee_id numeric,editor_msp_employee_id numeric,location_id numeric,Shop_order numeric)declare @rows as numericdeclare @str as varchar(8000) set @str='insert into #tbl(shop_id, shop_title,Shop_order, start_Date,Target_Date, end_Date, program_id, program_name, location,location_id, client,client_id) select s.shop_id,s.shop_title,s.Shop_order,s.shop_start_Date,s.shop_end_Date,p.program_end_Date,p.program_id,cast(p.program_id as varchar(20))+''/''+p.program_name,cast(l.location_id as varchar(20)) +''/''+ l.shopping_mall,l.location_id,cast(c.client_id as varchar(20)) + c.client_company_name,c.client_idfrom tbl_shops s inner join tbl_programs P on P.program_id = s.program_idinner join tbl_client_locations L on l.location_id = S.location_idinner join tbl_client C on C.client_id = l.client_idleft join tbl_scheduler_shop SS on SS.shop_id = S.shop_idleft join tbl_editor_shop ES on ES.shop_id = S.shop_idwhere ' +@searchexecute( @str)set @rows = @@rowcountif @rows=0 and @search1 <>''begin set @str='insert into #tbl(shop_id, shop_title, Shop_order,start_Date,Target_Date, end_Date, program_id, program_name, location,location_id, client,client_id)select s.shop_id,s.shop_title,s.Shop_orders.shop_start_Date,s.shop_end_Date,p.program_end_Date,p.program_id,cast(p.program_id as varchar(20))+''/''+p.program_name,cast(l.location_id as varchar(20)) +''/''+ l.shopping_mall,l.location_id,cast(c.client_id as varchar(20)) + c.client_company_name,c.client_idfrom tbl_shops s inner join tbl_programs P on P.program_id = s.program_idinner join tbl_client_locations L on l.location_id = S.location_idinner join tbl_client C on C.client_id = l.client_idleft join tbl_scheduler_shop SS on SS.shop_id = S.shop_idleft join tbl_editor_shop ES on ES.shop_id = S.shop_idwhere ' +@search1 execute( @str) set @rows= @@rowcountendselect @rows TOTAL_RECORDSdeclare @firstRec integerdeclare @lastRec integer set @firstRec = (@intPageNo - 1) * @intPageSize +1set @lastRec = (@firstRec + @intPageSize)-1if @intPageno=0 begin set @firstRec = 1 set @lastRec = @rowsendinsert into #tbl1(shop_id ,shop_title ,Shop_order,program_id ,program_name , shop_start_Date ,shop_end_Date , Target_Date ,location ,client_name,client_id)select shop_id ,shop_title ,Shop_order,program_id ,program_name , start_Date ,end_Date , Target_Date,location ,client,client_idfrom #tbl where id >= @firstRec and id<=@lastRecdeclare @sid as numericdeclare @name as varchar(200)declare @id as numericdeclare cor cursor for select shop_id from #tbl1 open corfetch next from cor into @sid while @@fetch_status =0 begin if(select count(*) from tbl_scheduler_shop where shop_id=@sid)>0 begin select @id= msp_employee_id, @name = cast(msp_employee_id as varchar(20))+'/' + last_name from tbl_msp_employee where msp_employee_id = (select msp_employee_id from tbl_scheduler_shop where shop_id=@sid) update #tbl1 set sche_msp_employee_id=@id, assigned_scheduler = @name where shop_id= @sid endif(select count(*) from tbl_editor_shop where shop_id=@sid)>0 begin select @id= msp_employee_id, @name = cast(msp_employee_id as varchar(20)) +'/'+ last_name from tbl_msp_employee where msp_employee_id = (select msp_employee_id from tbl_editor_shop where shop_id=@sid) update #tbl1 set editor_msp_employee_id=@id, assigned_editor = @name where shop_id= @sid end fetch next from cor into @sid endclose cordeallocate corselect * from #tbl1drop table #tbldrop table #tbl1GO
is there any Optimization prblems? or any thing else? OR how should i update my stored procedure to eleminate this problem.Please help me out from this problemMuhammad Saifullah