Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a little problem with executing a query. I don't know why, but it takes more time than expected.

When I run the following method, which is called after button click "Draw Groups" (I have an IS for Beach Volleyball... Tournaments and theirs Groups, Teams, Players, Matches...), it throws: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

C#
protected void btnDrawGroups_Click(object sender, EventArgs e)
    {
        Client client = new Client();
        try
        {
            client.Connect();
            client.Command = client.Connection.CreateCommand();
            client.Command.CommandText = "Draw_Groups";
            client.Command.CommandType = System.Data.CommandType.StoredProcedure;
            client.Command.Parameters.Add("@return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            client.Command.Parameters.Add("@Tour_ID", SqlDbType.VarChar).Value = GridView1.Rows[0].Cells[1].Text;
            client.Command.ExecuteNonQuery();
            client.Disconnect();
            int output = (int)client.Command.Parameters[0].Value;
            if (output == 0)
            {
                lblDrawn.Visible = true;
                lblDrawn.Text = "Nepodařilo se vygenerovat skupiny!"; 
            }
            else
            {
                lblDrawn.Visible = true;
                lblDrawn.Text = "Skupiny vygenerovány!";
            }
        }
        catch (Exception)
        {
            
            throw;
        }


When I debug the stored procedure Draw_Groups, it stop right here and does not continue:
SQL
Set @Celkovy_Pocet_Tymu = (select count(*) from Registration where Tournament_ID = @Tour_ID and Group_Name = 'RP')


Draw_Groups method:
SQL
CREATE PROCEDURE Draw_Groups 
	-- Add the parameters for the stored procedure here
	@Tour_ID int
AS
	Declare Team_IDs Cursor for Select Team_ID from Registration where Tournament_ID = @Tour_ID and Group_Name = 'RP' order by Datum_Registrace
	Declare @Group_Counter int
	Set @Group_Counter = (select count (Group_Name) from Beach_Group where Tournament_ID = @Tour_ID)-4
	Declare @Team_ID int
	Declare @Celkovy_Pocet_Tymu int 
	Set @Celkovy_Pocet_Tymu = (select count(*) from Registration where Tournament_ID = @Tour_ID and Group_Name = 'RP')
	Declare @Pocet_Tymu_Ve_Skupine int
	Declare @Group_Name Varchar (5)
	Declare @Datum_Registrace Datetime
BEGIN
	Begin try
		SET IMPLICIT_TRANSACTIONS OFF 
		begin transaction
			open Team_IDs
			Fetch NEXT from Team_IDs into @Team_ID 
			While @@Fetch_Status = 0 
			begin
				Set @Group_Name = (SELECT TOP (1) Group_Name FROM Beach_Group where Tournament_ID = @Tour_ID and Group_Name not like 'R%' ORDER BY NEWID())
				--
				while @Pocet_Tymu_Ve_Skupine >= @Celkovy_Pocet_Tymu/@Group_Counter begin
					if @Group_Name = 'A' begin
						Set @Group_Name = 'B'
					end
					else if @Group_Name = 'B' begin
					
						if @Group_Counter > 2 begin
							Set @Group_Name = 'C'
						end
						else begin
							Set @Group_Name = 'A'
						end
					end
					else if @Group_Name = 'C' begin
					
						if @Group_Counter > 3 begin
							Set @Group_Name = 'D'
						end
						else begin
							Set @Group_Name = 'A'
						end
					end
					else if @Group_Name = 'D' begin
					
						if @Group_Counter > 4 begin
							Set @Group_Name = 'E'
						end
						else begin
							Set @Group_Name = 'A'
						end
					end
					else if @Group_Name = 'E' begin
					
						if @Group_Counter > 5 begin
							Set @Group_Name = 'F'
						end
						else begin
							Set @Group_Name = 'A'
						end
					end
					else if @Group_Name = 'F' begin
						Set @Group_Name = 'A'
					end
				end
				--
				Set @Datum_Registrace = (select Datum_Registrace from Registration where Tournament_ID = @Tour_ID and Team_ID = @Team_ID)	
				update Registration set Group_Name = @Group_Name where Tournament_ID = @Tour_ID and Team_ID = @Team_ID
			end
		commit transaction
		return 1
	End Try
	begin Catch
		rollback
		return 0
	end Catch
END


Could any solve the problem with Timeout?

One more question... After some time, the debug continues. Why does Fetch NEXT does not work? It cycles in while cycle round and round with Team_ID 13...

Thanks

-Pepin z Hané
Posted
Updated 22-Oct-12 8:39am
v3
Comments
a1mimo 22-Oct-12 13:45pm    
have you tried to set the timeout of your sql server to higher number than 600 cause it seems to be that this operation takes more time than the server allows
Pepin z Hane 22-Oct-12 14:14pm    
It takes 10 minutes, there are two registrations in the database :-D, what if there will be 20 registration to one tournament and 100000 tournaments... imposible to durate so long.
a1mimo 22-Oct-12 14:19pm    
You can't know because there is too many factors that may affect the time simply if your processor is working in high percentage the shortest call to the server ever may give you time out try make it 0 and see if it works or no after all you have nothing to lose :-)

1 solution

Add this to your catch block:
select error_number() Number, error_severity() Severity, error_state() [State], error_procedure() [Procedure], error_line() Line, error_message() [Message]
and see what you get. You can act on that: at the moment there is no way to know why it might stop there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900