D
DarthMacgyver
Hello,
I recently wrote a survey application. Each question is very similar.
The first questions gives me a problem when there are multiple people
taking the survey (The Database connection Timed out) I am using the
Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000.
In there first question there can be up to 27 answers. So I figured
instead of making 27 different trips to the database I woulc just
concatenate my answers on the Stored Procedure and loop through them
and inserting them into my Answers table using a CURSOR. This all
worked great until I stress tested the application. I really think my
problem is that the CURSOR just has way to much overhead when multiple
people will be running the stored procedure.
What I am looking for is an alternative to using a cursor or if
someone could tell me what I am doing wrong (I am sure I am doing
something stupid ). Any help would be great.
Also the error I am getting in testing is:
Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding.
I included the Stored procedure that I mentioned above.
CREATE PROCEDURE dbo.usp_InsertQ1(
@UserName varchar(7),
@FinishedQuestion int,
@A1 varchar(1)=0,@A2 varchar(1)=0,@A3 varchar(1)=0,@A4
varchar(1)=0,@A5 varchar(1)=0,@A6 varchar(1)=0,@A7 varchar(1)=0,@A8
varchar(1)=0,@A9 varchar(1)=0,@A10 varchar(1)=0,@A11 varchar(1)=0,@A12
varchar(1)=0,
@A13 varchar(1)=0,@A14 varchar(1)=0,@A15 varchar(1)=0,@A16
varchar(1)=0,@A17 varchar(1)=0,@A18 varchar(1)=0,@A19
varchar(1)=0,@A20 varchar(1)=0,@A21 varchar(1)=0,@A22
varchar(1)=0,@A23 varchar(1)=0,@A24 varchar(1)=0,
@A25 varchar(1)=0,@A26 varchar(1)=0,@A27 varchar(1)=0, @UserDepartment
varchar(50),@CostCenter varchar(6)
)
AS
SET NOCOUNT ON
DECLARE @QuestionID char(11),
@NewSurveyID uniqueidentifier,
@SurveyIDforInsert int ,
@AnsNumber int,
@ConAnswers varchar(27),
@myAnswer int,
@RealUserDept int
SET @NewSurveyID = newid()
SET @AnsNumber = 1
SET @ConAnswers = (@A1 + @A2 + @A3 + @A4 + @A5 + @A6 + @A7 + @A8 + @A9
+ @A10 + @A11 + @A12 + @A13 + @A14 + @A15
+ @A16 + @A17 + @A18 + @A19 + @A20 + @A21 + @A22 + @A23 +
@A24 + @A25 + @A26 + @A27)
SELECT @RealUserDept = ccDepartmentID FROM t_CostCenters WHERE
ccCostCenter = @CostCenter
--Insert a new Survey since this is the First Question!
INSERT INTO t_Survey(
ID,
Name,
FinishedQuestion,
DepartmentFK,
CostCenter)
VALUES(@NewSurveyID,
@UserName,
@FinishedQuestion,
@RealUserDept,
@CostCenter)
--Get the Newly Inserted Survey ID
SELECT @SurveyIDforInsert =SurveyID FROM t_Survey WHERE ID =
@NewSurveyID
DECLARE c1 CURSOR FOR
SELECT qQuestionID
FROM t_Question
WHERE Left(qSequence,3) = 'Q01'
ORDER BY qQuestionID
OPEN c1
FETCH NEXT FROM c1
INTO @QuestionID
WHILE @@FETCH_STATUS = 0
BEGIN
IF SUBSTRING(@ConAnswers, @AnsNumber, 1) = 0
BEGIN
SET @myAnswer = NULL
END
ELSE
BEGIN
SET @myAnswer = SUBSTRING(@ConAnswers, @AnsNumber, 1)
END
INSERT INTO t_Answers (
aSurveyFK,
aQuestionFK,
aAnswer)
VALUES(@SurveyIDforInsert,
@QuestionID,
@myAnswer
)
SET @AnsNumber = @AnsNumber +1
FETCH NEXT FROM c1
INTO @QuestionID
END
CLOSE c1
DEALLOCATE c1
GO
I recently wrote a survey application. Each question is very similar.
The first questions gives me a problem when there are multiple people
taking the survey (The Database connection Timed out) I am using the
Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000.
In there first question there can be up to 27 answers. So I figured
instead of making 27 different trips to the database I woulc just
concatenate my answers on the Stored Procedure and loop through them
and inserting them into my Answers table using a CURSOR. This all
worked great until I stress tested the application. I really think my
problem is that the CURSOR just has way to much overhead when multiple
people will be running the stored procedure.
What I am looking for is an alternative to using a cursor or if
someone could tell me what I am doing wrong (I am sure I am doing
something stupid ). Any help would be great.
Also the error I am getting in testing is:
Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding.
I included the Stored procedure that I mentioned above.
CREATE PROCEDURE dbo.usp_InsertQ1(
@UserName varchar(7),
@FinishedQuestion int,
@A1 varchar(1)=0,@A2 varchar(1)=0,@A3 varchar(1)=0,@A4
varchar(1)=0,@A5 varchar(1)=0,@A6 varchar(1)=0,@A7 varchar(1)=0,@A8
varchar(1)=0,@A9 varchar(1)=0,@A10 varchar(1)=0,@A11 varchar(1)=0,@A12
varchar(1)=0,
@A13 varchar(1)=0,@A14 varchar(1)=0,@A15 varchar(1)=0,@A16
varchar(1)=0,@A17 varchar(1)=0,@A18 varchar(1)=0,@A19
varchar(1)=0,@A20 varchar(1)=0,@A21 varchar(1)=0,@A22
varchar(1)=0,@A23 varchar(1)=0,@A24 varchar(1)=0,
@A25 varchar(1)=0,@A26 varchar(1)=0,@A27 varchar(1)=0, @UserDepartment
varchar(50),@CostCenter varchar(6)
)
AS
SET NOCOUNT ON
DECLARE @QuestionID char(11),
@NewSurveyID uniqueidentifier,
@SurveyIDforInsert int ,
@AnsNumber int,
@ConAnswers varchar(27),
@myAnswer int,
@RealUserDept int
SET @NewSurveyID = newid()
SET @AnsNumber = 1
SET @ConAnswers = (@A1 + @A2 + @A3 + @A4 + @A5 + @A6 + @A7 + @A8 + @A9
+ @A10 + @A11 + @A12 + @A13 + @A14 + @A15
+ @A16 + @A17 + @A18 + @A19 + @A20 + @A21 + @A22 + @A23 +
@A24 + @A25 + @A26 + @A27)
SELECT @RealUserDept = ccDepartmentID FROM t_CostCenters WHERE
ccCostCenter = @CostCenter
--Insert a new Survey since this is the First Question!
INSERT INTO t_Survey(
ID,
Name,
FinishedQuestion,
DepartmentFK,
CostCenter)
VALUES(@NewSurveyID,
@UserName,
@FinishedQuestion,
@RealUserDept,
@CostCenter)
--Get the Newly Inserted Survey ID
SELECT @SurveyIDforInsert =SurveyID FROM t_Survey WHERE ID =
@NewSurveyID
DECLARE c1 CURSOR FOR
SELECT qQuestionID
FROM t_Question
WHERE Left(qSequence,3) = 'Q01'
ORDER BY qQuestionID
OPEN c1
FETCH NEXT FROM c1
INTO @QuestionID
WHILE @@FETCH_STATUS = 0
BEGIN
IF SUBSTRING(@ConAnswers, @AnsNumber, 1) = 0
BEGIN
SET @myAnswer = NULL
END
ELSE
BEGIN
SET @myAnswer = SUBSTRING(@ConAnswers, @AnsNumber, 1)
END
INSERT INTO t_Answers (
aSurveyFK,
aQuestionFK,
aAnswer)
VALUES(@SurveyIDforInsert,
@QuestionID,
@myAnswer
)
SET @AnsNumber = @AnsNumber +1
FETCH NEXT FROM c1
INTO @QuestionID
END
CLOSE c1
DEALLOCATE c1
GO