Forum Moderators: open

Message Too Old, No Replies

Help

type mismatch

         

wweidner

3:09 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



I have a register page (which works), but then it sends the user to the log in page, the info is getting put into the database( i have checked that) but when i run it i am getting:

"Microsoft VBScript runtime error '800a000d'

Type mismatch: 'stconn'

/members.asp, line 10

Which i am not understanding why. Here is the code

<!-- #include file="includes/connection.inc" -->
**This is the Connection File**
<%
Set cn=Server.CreateObject("ADODB.Connection")
cn.Mode=3
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("../data/backend.mdb") & ";"
cn.Open strconn
function EncodeThisText(text)
if(instr(text, "'")) then
text = replace(text, "'", "&#39;")
elseif(instr(text, """")) then
text = replace(text, """", "&#34;")
end if
EncodeThisText = text
end function
%>**End Of Connection file**

<%
if session("user_name") = false or session("password") = false then
response.redirect "login.asp"
end if
name = session("name")
user_name = session("user_name")
password = session("password")
**(line 10)**stconn "Select * From users Where user_name = '" & user_name & "'"

'strSQL = "SELECT field1, field2 FROM table1"
stconn.Open stconnSQL, stconnConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
if stconn.eof then
response.redirect "login.asp"
else
if stconn("password") <> password then
response.redirect "login.asp"
end if
end if
%>
I have tried different things that were suggested, while i was looking everywhere. Any ideas?

duckhunter

5:01 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Could it be as simple as the = sign?

stconn = "Select * From users Where user_name = '" & user_name & "'"

wweidner

6:16 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Well that was a really silly mistake.. that is fixed...now i am getting this error

Microsoft VBScript runtime error '800a01a8'

Object required: 'stconn'

/members.asp, line 12

it is the same code as posted in the first message, but here is line 12

stconn.Open stconnSQL, stconnConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

mattglet

6:26 pm on Jun 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of stconn.open, do cn.open. cn is your connection object, not stconn.

-Matt

mattglet

6:27 pm on Jun 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In fact, replace all your stconn with cn. stconn isn't initialized at all in your code. Where is it coming from?

-Matt

wweidner

6:39 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



ok..that was from when i was trying to fix it before asking for help....it is still giving me the same error...

Microsoft VBScript runtime error '800a01a8'

Object required: 'cn'

/members.asp, line 12

same line

cn.Open cnSQL, cnConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

when i take that line out it gives me this error

Microsoft VBScript runtime error '800a01a8'

Object required: 'cn'

/members.asp, line 13

and line 13 is

if cn.eof then

which i know i need to have the connection openned before it can run the eof check.

I have also tried taking everthing off of line 12 so that it is only

cn.Open

and that is still giving the same error

Microsoft VBScript runtime error '800a01a8'

Object required: 'cn'

/members.asp, line 12

mattglet

9:07 pm on Jun 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something is wrong with your include file then. For whatever reason, the data in the include is not available to the page you are trying to debug. The 'cn' object is located in the include file, but it's not being initialized.

-Matt

duckhunter

12:05 am on Jun 17, 2004 (gmt 0)

10+ Year Member



First off, if referencing a variable from another file via include, you must declare it above the include.

Secondly, You need a recordset for the results. Also, simplify the steps instead of trying to do everything on one line/statement.

Dim cn
'put this above the INCLUDE statement so the include file uses your local variable.

'Open the Connection
Set cn=Server.CreateObject("ADODB.Connection")
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("../data/backend.mdb") & ";"
cn.Open strconn

'Now the Recordset
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn
rs.CursorType = adOpenForwardOnly

strSQL = Select * From users Where user_name = '" & user_name & "'"

rs.open strSQL

'Now cycle through the results
Do While Not rs.EOF
Response.write rs.Fields("fieldnamehere") & "<BR>"
Loop

'Now clean up

cn.close
rs.close
cn = nothing
rs = nothing

wweidner

2:20 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Thank you DuckHunter...that got it working that it goes to the "members page" but at the bottom of the page it is giving me an error.

Here is the code and how it was changed, I am not including the include file this time. I didn't make any changes to it.

<!-- #include file="includes/connection.inc" -->
<%
Dim cn
<***this was above the inclued file but it was showing up on the page, so i moved it down.**>

if session("user_name") = false or session("password") = false then
response.redirect "login.asp"
end if
name = session("name")
user_name = session("user_name")
password = session("password")

Set cn=Server.CreateObject("ADODB.Connection")
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("../data/backend.mdb") & ";"
cn.Open strconn

Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = cn
rs.CursorType = adOpenForwardOnly

strSQL = "Select * From users Where user_name = '" & user_name & "'"

rs.open strSQL

if rs.eof then
response.redirect "login.asp"
else
if rs("password") <> password then
response.redirect "login.asp"
end if
end if
%>

This is more of the ASP that is on the page.
<%
if session("discount") = "true" then
response.write ("<script type=""text/javascript"">window.open(""special.asp"","""",""height=322, width=374, top=50, left=50"")</script>")
end if
%>

this at the very bottom of the page, reason it was not doing what it was suppose to, it would give me and error:

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

So then i moved it to the bottom of the page and it work except that i am getting and error on the bottom of the page. I have it right before the body closes. Code first:

<%
cn.close
rs.close
cn = nothing
rs = nothing
%>

Now the error i get when i run it the way i have it. (which is the error on the webpage itself.)

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

/members.asp, line 72

this is line 72

**rs.close**

I just relized that when i run it either way, it is giving me a problem at the "rs.close" line, no matter where i have it setting.

defanjos

6:29 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do it this way:

<%
rs.close
set rs = nothing
cn.close
set cn = nothing
%>

first close the rs, then the cn

duckhunter

6:47 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Sorry I didn't actually test that code. You can also put an "On Error Resume Next" above the cleanup routine. That way if it hits an error your page doesn't fail, it just continues on without showing errors.

wweidner

7:01 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Thank you ....that fixed it