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.
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:
Set @Celkovy_Pocet_Tymu = (select count(*) from Registration where Tournament_ID = @Tour_ID and Group_Name = 'RP')
Draw_Groups method:
CREATE PROCEDURE Draw_Groups
@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é