Subject: recordset problem
Posted By: jdsflash Post Date: 5/16/2006 10:53:33 AM
Im attempting to build my first asp application. I cant seem to get past this first hump will someone point out what im doing wrong please.
Im getting this error:

ADODB.Recordset error '800a0e7d'

The connection cannot be used to perform this operation. It is either closed or invalid in this context.

/text.asp, line 10



<%@ Language=VBScript %>
<%
dim rstData2, strConnection2, cnData2, varSQL2, strRDir,strTemp
Set cnData2 = Server.CreateObject("ADODB.Connection") 
strConnection2 = "Driver={SQL Server}; server=wisconline;Database=RegFlex; UID=josh; PWD=flexo"
cnData2.Open strConnection2
DIM cn, rs, LoopCount
Set rstData2 = Server.CreateObject("ADODB.Recordset")
varSQL2 = "SELECT * FROM regflexo"
rstData2.Open varSQL2 
LoopCount = 1
If rstData2.EOF Then
    Write("something")
Else
    Write("<table border=0 width='100%' cellpadding=2 cellspacing=1 bgcolor=white>")
    Response.Write("<ol>")
    Do While Not rstData2.EOF ' Loop starts until end of recordset
        LoopCount = LoopCount + 1
        Response.Write("<li>" & rstData2("column1").Value & "<br>")        
        rstData2.MoveNext
    Loop
    Response.Write("</ol>")
End If
rstData2.Close
Set rstData2 = Nothing
cnData2.Close
Set cnData2 = Nothing
%>



Reply By: rstelma Reply Date: 5/16/2006 11:49:11 AM
Got this code working.

I would suggest using the 'sa' account to get started since its one less thing you've got to worry about, database permissions.

You were also missing a "Response." in the first part of the "If" statement but since it looks like you had data in the table then you weren't going to get in there anyway.

Looks pretty good for a first start.

    dim rstData2, strConnection2, cnData2, varSQL2
    Set cnData2 = Server.CreateObject("ADODB.Connection") 
    strConnection2 = "Provider=SQLOLEDB.1;Persist Security Info=False;Server=[servername];UID=sa;Password=[password];Database=[database name];"
    cnData2.Open strConnection2

    varSQL2 = "SELECT * from regoflex;"
    Set rstData2 = cnData2.Execute(varSQL2)
    If rstData2.EOF Then
        Response.Write("something")
    Else
        Response.Write("<table border=0 width='100%' cellpadding=2 cellspacing=1 bgcolor=white>")
        Response.Write("<ol>")
        Do While Not rstData2.EOF ' Loop starts until end of recordset
            Response.Write("<li>" & rstData2("column1").Value & "<br>")        
            rstData2.MoveNext
        Loop
        Response.Write("</ol>")
    End If
    rstData2.Close
    Set rstData2 = Nothing
    cnData2.Close
    Set cnData2 = Nothing



Go to topic 43174

Return to index page 286
Return to index page 285
Return to index page 284
Return to index page 283
Return to index page 282
Return to index page 281
Return to index page 280
Return to index page 279
Return to index page 278
Return to index page 277