PDA

View Full Version : code error


scroots
12-06-2002, 11:02 PM
the following error is produced with my piece of code, i think it may be the connection string.


<% @LANGUAGE = VBSCRIPT %>
<% Option Explicit %>
<%
Dim uname, pword
uname = Request.Form("uname")
pword = Request.Form("pword")

Dim cmdGetUser, rsGetUser
Set cmdGetUser = Server.CreateObject.Command
cmdGetUSer.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("peeps.mdb")
cmdGetUser.CommandText = "SELECT * FROM tbl_Users WHERE tblUsers.Username = '" & uname '""
cmdGetUser.CommandType = adCmdText

Set rsGetUser = cmdGetUser.Execute

Set cmdGetUser = Nothing

While Not rsGetUser.EOF

If UCase(uname) = Ucase(rsGetUser("username")) Then
If UCase(pword) = Ucase(rsGetUser("password")) Then
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
Else
Response.Redirect "default.asp?error=password"
End If
Else
Response.Redirect "default.asp?error=username"
End If

rsGetUser.Close()
Set rsGetUser = Nothing
Wend
%>



and the error message is:
Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Server.CreateObject'

/es/login/checklogin.asp, line 9

i presume it is my connection string but i may be wrong, anyone spot any other mistakes?

cheers
scroots

Roy Sinclair
12-06-2002, 11:08 PM
Try changing this: Set cmdGetUser = Server.CreateObject.Command

to this:

Set cmdGetUser = Server.CreateObject("ADODB.Command")

Roy Sinclair
12-06-2002, 11:14 PM
Actually, I think I'd code the whole thing more like this:


<% @LANGUAGE = VBSCRIPT %>
<% Option Explicit %>
<%
Dim uname, pword
uname = Request.Form("uname")
pword = Request.Form("pword")

Dim oConn,cmdGetUser, rsGetUser

Set oConn = Server.CreateObject("ADODB.Connection")
Set cmdGetUser = Server.CreateObject("ADODB.Command")
Set rsGetUser = Server.CreateObject("ADODB.Recordset")

oConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("peeps.mdb"))
cmdGetUSer.ActiveConnection = oConn
cmdGetUser.CommandText = "SELECT * FROM tbl_Users WHERE tblUsers.Username = '" & uname '""
cmdGetUser.CommandType = adCmdText

Set rsGetUser = cmdGetUser.Execute

Set cmdGetUser = Nothing

While Not rsGetUser.EOF

If UCase(uname) = Ucase(rsGetUser("username")) Then
If UCase(pword) = Ucase(rsGetUser("password")) Then
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
Else
Response.Redirect "default.asp?error=password"
End If
Else
Response.Redirect "default.asp?error=username"
End If

rsGetUser.Close ()
Set rsGetUser = Nothing
oConn.Close ()
Set oConn = nothing
Wend
%>

scroots
12-06-2002, 11:19 PM
roy i decided to use your way but one slight hitch, the code has an error and it bugs me as i enhanced my original code and got the same errror.


<% @LANGUAGE = VBSCRIPT %>
<% Option Explicit %>
<%
Dim uname, pword
uname = Request.Form("uname")
pword = Request.Form("pword")

Dim oConn,cmdGetUser, rsGetUser

Set oConn = Server.CreateObject("ADODB.Connection")
Set cmdGetUser = Server.CreateObject("ADODB.Command")
Set rsGetUser = Server.CreateObject("ADODB.Recordset")

oConn.Open ("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("peeps.mdb"))
cmdGetUSer.ActiveConnection = oConn
cmdGetUser.CommandText = "SELECT * FROM tblUsers WHERE tblUsers.Username = '" & uname '""
'cmdGetUser.CommandType = adCmdText

Set rsGetUser = cmdGetUser.Execute
i know have the error
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression 'tblUsers.Username = 'ace'.

what is the problem?

scroots

rcreyes
12-07-2002, 01:37 AM
when I printed your commandtext I noticed that it was missing an ' at the end of user name, for example

uname="john Doe"

This statement

cmdGetUser.CommandText = "SELECT * FROM tblUsers WHERE tblUsers.Username = '" & uname '""


If printed will produce the following:

SELECT * FROM tblUsers WHERE tblUsers.Username = 'john Doe

Notice that the ' in John Doe is missing. So the statement should be:

cmdGetUser.CommandText ="SELECT * FROM tbl_Users WHERE tblUsers.Username = '" & uname & "'"

Now print this will produce a correct syntax:


SELECT * FROM tblUsers WHERE tblUsers.Username = 'john Doe'

Thanks,
Ray

scroots
12-07-2002, 10:57 AM
rcreyes i changed my line of code to

cmdGetUser.CommandText = "SELECT * FROM tblUsers WHERE tblUsers.Username = '" & uname "'"

like you said but i get the error expected end of statement.

any ideas?
scroots

Roelf
12-07-2002, 02:18 PM
Originally posted by scroots
rcreyes i changed my line of code to

cmdGetUser.CommandText = "SELECT * FROM tblUsers WHERE tblUsers.Username = '" & uname & "'"

like you said but i get the error expected end of statement.

any ideas?
scroots

forgot an ampersand

scroots
12-07-2002, 02:54 PM
thank you so much

scroots