Hey folks,
I am having a very annoying problem with my ASP/SQL code and I am not sure if this is best suited for the SQL forum or the ASP forum, so I will post them in both places and ask for forgiveness later.
Anyway I am getting this error from my code:
"Command text was not set for the command object"
A user fills out a form with their email address. Hitting the submit button directs them to a "process.asp" file that validates the info and updates a database accordingly.
In the code I am selecting a users email adress from the database. If the email address is not found then I update the database with the users information. If the email is found, then the user is directed to a page that says "no duplicate emails allowed".
If an error occurs, I am emailed the sql statement along with the err number and error description. In the email the line that says "sql statement:" would be following by the sql statement.
but every now and then, and it is weird because this DOES NOT happen all the time, i get an error saying basically the following:
sql statement:''.
Description: Command text was not set for the command object.
Source: Microsoft OLE DB Provider for ODBC Drivers
Number: -2147217908
which basically tells me that there was no sql statement to process!!!! even though i explicitely declare a variable called "sql_insert", initialize it, and set it equal to an sql insert statement like
sql_insert = "insert into" & tableName & "(fname,lname,street,city,state,country,zip,email,datecreated) values ('"& fname &"','"& lname &"','"& street &"','"& city &"','"& state &"','"& country &"','"& zip &"','"& email &"',getDate())"
Here is the entire code of the process.asp file:
<%
dim conn, sql
sub connecttoDB()
set conn = server.createobject("ADODB.Connection"
conn.Open = "DSN=mydsn;UID=me;password=funkymamajamma"
end sub
sub disconnectfromDB()
set sql=nothing
conn.close
set conn = nothing
end sub
sub emailError(email,message, errdesc, errsource,errnumber)
message = message & VBCRLF & VBCRLF & "Description: " & errdesc & VBCrlf & "Source: " & errsource & VBCrlf & "Number: " & errnumber
dim objEmail
set objEmail = server.createobject("CDONTS.NewMail"
with objEmail
.To = email
.From = "webuser@mysite.com"
.Subject = "Error occured in process.asp"
.Body = message
.Send
end with
set objMsg = nothing
end sub
%>
'HERE I DECLARE AND INITIALIZE MY VARIABLES AND GET THE FORM DATA TO BE PROCESSED. (i left this out as this message is already pretty lengthy).
<%
'CONNECT TO THE DATABASE
connecttoDB
sql = "select email from userTable where email ='"& email & "' and lname='"& userlastname &"'"
set rs = conn.execute(sql)
if rs.eof then
'user does not already have an entry in the database
rs.close
set rs = nothing
disconnectfromDB
sql_insert = "insert into" & tableName & "(fname,lname,street,city,state,country,zip,email,datecreated) values ('"& userfirstname &"','"& userlastname &"','"& street &"','"& city &"','"& state &"','"& country &"','"& zip &"','"& email &"',getDate())"
connecttoDB
conn.BeginTrans()
conn.execute(sql_insert)
if err.number then
'if an error has occured, undo sql insert and email error.
conn.rollbacktrans
disconnectfromDB
emailError strEmailTo, "Database error. DB update failed."& vbcrlf &"Sql statement: ' "& sql_insert &" '.",err.description,err.source,err.number
response.redirect "error.asp?message=dbnotupdated"
else
conn.commitTrans()
disconnectfromDB
response.redirect "thanks.asp"
end if
else
'user already has an entry/email in the database.
disconnectfromDB
response.redirect "error.asp?message=duplicateemail"
end if
%>
I know it's a bit lengthy. But bear (sp?) with me.
The code works most of the time. But every now and then i get the error mentioned above (i.e. "Command text was not set for the command object."
and an empty string for the sql statment.
Any constructive criticism or thoughts on why this error occures would be greatly appreciated. Or if you have seen this happen before, then please enlighten me. Please!!!
I have been looking over this code for almost a week now and yet i cannot figure out why i am getting the weird error.
Thanks for your help.
-skurpyun
I am having a very annoying problem with my ASP/SQL code and I am not sure if this is best suited for the SQL forum or the ASP forum, so I will post them in both places and ask for forgiveness later.
Anyway I am getting this error from my code:
"Command text was not set for the command object"
A user fills out a form with their email address. Hitting the submit button directs them to a "process.asp" file that validates the info and updates a database accordingly.
In the code I am selecting a users email adress from the database. If the email address is not found then I update the database with the users information. If the email is found, then the user is directed to a page that says "no duplicate emails allowed".
If an error occurs, I am emailed the sql statement along with the err number and error description. In the email the line that says "sql statement:" would be following by the sql statement.
but every now and then, and it is weird because this DOES NOT happen all the time, i get an error saying basically the following:
sql statement:''.
Description: Command text was not set for the command object.
Source: Microsoft OLE DB Provider for ODBC Drivers
Number: -2147217908
which basically tells me that there was no sql statement to process!!!! even though i explicitely declare a variable called "sql_insert", initialize it, and set it equal to an sql insert statement like
sql_insert = "insert into" & tableName & "(fname,lname,street,city,state,country,zip,email,datecreated) values ('"& fname &"','"& lname &"','"& street &"','"& city &"','"& state &"','"& country &"','"& zip &"','"& email &"',getDate())"
Here is the entire code of the process.asp file:
<%
dim conn, sql
sub connecttoDB()
set conn = server.createobject("ADODB.Connection"
conn.Open = "DSN=mydsn;UID=me;password=funkymamajamma"
end sub
sub disconnectfromDB()
set sql=nothing
conn.close
set conn = nothing
end sub
sub emailError(email,message, errdesc, errsource,errnumber)
message = message & VBCRLF & VBCRLF & "Description: " & errdesc & VBCrlf & "Source: " & errsource & VBCrlf & "Number: " & errnumber
dim objEmail
set objEmail = server.createobject("CDONTS.NewMail"
with objEmail
.To = email
.From = "webuser@mysite.com"
.Subject = "Error occured in process.asp"
.Body = message
.Send
end with
set objMsg = nothing
end sub
%>
'HERE I DECLARE AND INITIALIZE MY VARIABLES AND GET THE FORM DATA TO BE PROCESSED. (i left this out as this message is already pretty lengthy).
<%
'CONNECT TO THE DATABASE
connecttoDB
sql = "select email from userTable where email ='"& email & "' and lname='"& userlastname &"'"
set rs = conn.execute(sql)
if rs.eof then
'user does not already have an entry in the database
rs.close
set rs = nothing
disconnectfromDB
sql_insert = "insert into" & tableName & "(fname,lname,street,city,state,country,zip,email,datecreated) values ('"& userfirstname &"','"& userlastname &"','"& street &"','"& city &"','"& state &"','"& country &"','"& zip &"','"& email &"',getDate())"
connecttoDB
conn.BeginTrans()
conn.execute(sql_insert)
if err.number then
'if an error has occured, undo sql insert and email error.
conn.rollbacktrans
disconnectfromDB
emailError strEmailTo, "Database error. DB update failed."& vbcrlf &"Sql statement: ' "& sql_insert &" '.",err.description,err.source,err.number
response.redirect "error.asp?message=dbnotupdated"
else
conn.commitTrans()
disconnectfromDB
response.redirect "thanks.asp"
end if
else
'user already has an entry/email in the database.
disconnectfromDB
response.redirect "error.asp?message=duplicateemail"
end if
%>
I know it's a bit lengthy. But bear (sp?) with me.
The code works most of the time. But every now and then i get the error mentioned above (i.e. "Command text was not set for the command object."
Any constructive criticism or thoughts on why this error occures would be greatly appreciated. Or if you have seen this happen before, then please enlighten me. Please!!!
I have been looking over this code for almost a week now and yet i cannot figure out why i am getting the weird error.
Thanks for your help.
-skurpyun