Riders
Riders

Reputation: 19

Internal Error from database Connection

I'm a beginner in asp, and I am having trouble with this code. I have tried many times to debug, but it still wouldn't work. When I run the code, It is showing, internal server error 500. I'm not sure what is wrong. If I remove this chunk of code, it will work. Can someone please help me and point me to the right direction? Please?

<%
strSQL = "SELECT _id,name,price,out_of_stock FROM class_product WHERE purchase_form = 1 ORDER BY _rank ASC"

OpenMainConn()
set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.Open strSQL, MainDBConn
dim count
if not rsProducts.eof then
    dim exceptions
    while not rsProducts.eof
        count = count + 1
        exceptions = exceptions & "product" & count & ","
%>
<tr>
    <td>
        <%=(rsProducts("name"))%>
    </td>
    <td align="right">
        <%=(FormatCurrency(rsProducts("price"),2))%>
    </td>
    <td align="center">
    <% if rsProducts("out_of_stock") = 0 then %>
        <input type="text" class="input_text" style="width: 20px;" id="product<%=count %>" name="product<%=count %>" onchange="updateSub();" />
    <% else %>
        <img border="0" src="images/OUT-OF-STOCK.gif"/><input type="hidden" class="input_text" style="width: 20px;" id="product<%=count %>" name="product<%=count %>" onchange="updateSub();" />
    <% end if %>
        <input type="hidden" id="productDetails<%=count %>" name="productDetails<%=count %>" value="<%=(rsProducts("name") & "|" & rsProducts("price"))%>" />
    </td>
</tr>
<%
        rsProducts.movenext()
    wend
end if
rsProducts.Close()
set rsProducts = nothing
CloseMainConn()
%>

Upvotes: 1

Views: 221

Answers (1)

Nicholas Murray
Nicholas Murray

Reputation: 13533

Your main issue is in your database connection.

Try bypassing it with the following (which you can adjust)

'OpenMainConn() 
Set MainDBConn = Server.CreateObject("ADODB.Connection")
MainDBConn.open "Provider=SQLOLEDB.1;Password=ppppppppp;Persist Security Info=True;User ID=xxxxxx;Initial Catalog=Test;Data Source=123-AAAAA11111\SQLEXPRESS;"

Also you should close your connection like below

If rsProducts.State = adStateOpen Then
   rsProducts.Close
End If
Set rsProducts = Nothing

Upvotes: 1

Related Questions