Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

segment of code stopping the network

Status
Not open for further replies.

chaos986

Programmer
Sep 22, 2000
4
US
I cornered the bad code to this segment but cannot find it.


Set RS = objConn.Execute("UPDATE Questions SET question = ('" & question & "') WHERE (ContentPage, QNumb) = ('" & ContentPage & "','" & QNumb & "')")
For a=1 to Choices
Set RS = objConn.Execute("UPDATE Answers SET (order, correct, answer, reason) = ('" & a & "','" & Correct(a) & "','" & Answer(a) & "','" & Reason(a) & "') WHERE (ContentPage, QNumb) = ('" & ContentPage & "','" & QNumb & "')")
Next [sig][/sig]
 
Can you be a little more detailed, like what kind of error, what's your connection, so forth, no offense but just throwing code in our face and saying &quot;Fix It&quot; doesnt help us determine the error very well esepecially since we dont even know if some of the variables are valid as well. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
sorry. I've been working with this for 2 days am frustrated.

That piece of code is part of a processing script for a form which adds questions to a database. I am editing the code on a developmental server on our network. When i submit question the entire dev. server stops and must be restarted. It only happens when this segment of code is trying to exicute. The error message is server can not be reached.

entire code:<%
PageFunction=Request.Form(&quot;Pagefunction&quot;)
Choices=Request.Form(&quot;Choices&quot;)
ContentPage=Request.Form(&quot;Page&quot;)
Question=Request.Form(&quot;Question&quot;)
QNumb=Request.Form(&quot;QuestionChoice&quot;)
Dim Answer(10), Reason(10), Correct(10)
CorrectCounter=0
For a=1 to Choices
Answer(a)=Request.Form(&quot;Answer(&quot; & a & &quot;)&quot;)
Reason(a)=Request.Form(&quot;Reason(&quot; & a & &quot;)&quot;)
If Request.Form(&quot;Correct(&quot; & a & &quot;)&quot;)=&quot;yes&quot; Then
Correct(a)=&quot;correct&quot;
CorrectCounter=CorrectCounter+1
Else
Correct(a)=&quot;*&quot;
End If
Next

If CorrectCounter=0 Then
Response.Write(&quot;You have designated no answer as the correct answer.<BR>Please use the back button on the browser to return to the form and change your selections to one correct answer.&quot;)
Else
If CorrectCounter>1 Then
Response.Write(&quot;You have designated more than one answer as the correct answer.<BR>Please use the back button on the browser to return to the form and change your selections to one correct answer.&quot;)
Else
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;Content_and_Links&quot;
If PageFunction<>&quot;edit&quot; Then
Set RS = objConn.Execute(&quot;INSERT INTO Questions (ContentPage, QNumb, question) VALUES ('&quot; & ContentPage & &quot;','&quot; & QNumb & &quot;','&quot; & question & &quot;')&quot;)
For a=1 to Choices
Set RS = objConn.Execute(&quot;INSERT INTO Answers (ContentPage, QNumb, order, correct, answer, reason) VALUES ('&quot; & ContentPage & &quot;','&quot; & QNumb & &quot;','&quot; & a & &quot;','&quot; & Correct(a) & &quot;','&quot; & Answer(a) & &quot;','&quot; & Reason(a) & &quot;')&quot;)
Next
Else
Set RS = objConn.Execute(&quot;UPDATE Questions SET question = ('&quot; & question & &quot;') WHERE (ContentPage, QNumb) = ('&quot; & ContentPage & &quot;','&quot; & QNumb & &quot;')&quot;)
For a=1 to Choices
Set RS = objConn.Execute(&quot;UPDATE Answers SET (order, correct, answer, reason) = ('&quot; & a & &quot;','&quot; & Correct(a) & &quot;','&quot; & Answer(a) & &quot;','&quot; & Reason(a) & &quot;') WHERE (ContentPage, QNumb) = ('&quot; & ContentPage & &quot;','&quot; & QNumb & &quot;')&quot;)
Next
End If
ObjConn.Close
Set ObjConn=nothing
End If
End If

%>
[sig]<p>Mike2<br><a href=mailto:chaos986@yahoo.com>chaos986@yahoo.com</a><br><a href=http// Mike2 Website</a><br>also see my small busness work @ http:/www.michaelswgp.com[/sig]
 
I'm kind of a bit stumped myself (I Get off work in 20 mins, so will have more time to concentrate on it when I Get home) I can understand fustration, I've been there numerous times, also I noticed you are using a correct, but simpler way of getting a recordset, just so you know when you do not need a recordset to execute commands like Insert, and update that have no return of an opened recordset, so you do not need to &quot;Set RS =&quot; a longer way, but more explanitory(and might help you avoid errors) is to use a Command Object.

this is a quick thing out of VB, you can easily alter it to ASP

[tt]
Dim Conn As ADODB.Connection
Dim Com As ADODB.Command

Com.ActiveConnection = Conn
Com.CommandType = adCmdText 'adCmdText = 1
Com.CommandText = &quot;your SQL String here&quot;
Com.Execute
[/tt]

you could also do Set RS = Com.eXecute, but your recordset would come back with I belive forwardonly cursor, and KeySet(or was it Static) lock. so kinda of limited if you try to use a command object to return a recordset.

if you do need to open a recordset for reading

RS.Open &quot;TheSQL String&quot;, ActiveConnection, CursorType, LockType

by defining your own cursors, and locks when opening a recordset can keep you from running into problems in the future, for example if you try to open a cursor that allows writing, the server might reject it, so then you'd chose a cursor that does static or readonly.

I'll look some more into it after I get off work, and stop by the grocery store.

Note : if you need to gaze at the code tonight, stare at it for 20 mins, then take 10 min breaks, it has been proven that most of the time, you brain remebers the first 10 mins and the last 10 mins, so that way you can absorb that 20 min time, and take a break for about 10 mins. each time. :)I [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top