Push to active directory fails without error - asp-classic

I apologise if I have posted this before, but I am struggling with this script to push data into Active Directory. The following code works, i.e. it does not produce any errors, but it doesn't update the directory. I have the following code:
<%# Language=VBScript %>
<% response.Buffer = True
'Define the AD OU that contains our users
dim ADUser, user, firstname, lastname, email, telephonenumber, mobile, description
'This initializes all of our variables
user = request.querystring("account_name")
'This puts the value of the account_name into a variable
if len(user) = 0 then
'If the length of the username is equal to 0
response.write "Please supply a username in the query string"
elseif len(user) > 0 then
'Else is length of user is greater than 0
ADUser = "LDAP://OU=RBC Staff,OU=RBC Users,DC=rugby,DC=internal"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\User"
objCon.Properties("Password") = "Password01"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select givenName,sn,mail,telephonenumber,mobile,description, sAMAccountName, cn FROM '"+ ADUser +"' where sAMAccountname='"& user &"'"
Set objRS = objCom.Execute
If IsNull(objRS.Fields("Description").Value) Then
sDesc = ""
else
For Each item In objRS.Fields("description").Value
sDesc = item
Next
end if
if isNull(objRS("givenName")) then
firstname = ""
else
firstname = objRS("givenName")
end if
if isNull(objRS("sn")) then
lastname = ""
else
lastname = objRS("sn")
end if
if isNull(objRS("mail")) then
email = ""
else
email = objRS("mail")
end if
if isNull(objRS("telephonenumber")) then
telephonenumber = ""
else
telephonenumber = objRS("telephonenumber")
end if
if isNull(objRS("mobile")) then
mobile = ""
else
mobile = objRS("mobile")
end if
Response.Write "<form action='editentry.asp?account_name=" & user &"' method='POST'>"
Response.Write "<table>"
Response.Write "<tr>"
Response.Write "<td><label for='firstname'>Firstname</label></td>"
Response.Write "<td><input type='text' id='firstname' value='" + firstname + "' name='firstname'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><label for='lastname'>Lastname</label></td>"
Response.Write "<td><input type='text' id='lastname' value='" & lastname & "' name='lastname'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><label for='email'>E-Mail Address</label></td>"
Response.Write "<td><input type='email' id='email' value='" + email + "' name='email'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><label for='description'>Description</label></td>"
Response.Write "<td><input type='text' id='description' value='" + sDesc + "' name='description'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><label for='mobile'>Mobile</label></td>"
Response.Write "<td><input type='text' name='mobile' value='" + mobile + "' id='mobile'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><label for='telephonenumber'>Telephone Number</label></td>"
Response.Write "<td><input type='text' id='telephonenumber' value='" + telephonenumber + "' name='telephonenumber'></td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td><input type='hidden' name='subval' value='1'></td>"
Response.Write "<td><input type='submit' name='submit''></td>"
Response.Write "</tr>" + vbCrLf
Response.Write "</table>"
Response.Write "</form>"
if request.form("subval")=1 then
'If the subval field equals 1, we know the form has been submitted OK
firstname = request.form("firstname")
lastname = request.form("lastname")
email = request.form("email")
telephonenumber = request.form("telephonenumber")
mobile = request.form("mobile")
Set update = CreateObject("ADODB.Command")
Set update.ActiveConnection = objCon
update.CommandText ="select ADsPath, givenName,sn,mail,telephonenumber,mobile,sAMAccountName FROM '"+ ADUser +"' where sAMAccountname='"& user & "'"
Set update.ActiveConnection = objCon
update.Properties("searchscope") = ADS_SCOPE_ONELEVEL
set writeLDAP = update.Execute
Do While Not writeLDAP.EOF
Set usr = GetObject(writeLDAP.Fields("ADsPath").Value)
usr.Put "gjvenName", firstname
usr.Put "sn", lastname
usr.Put "mail", email
usr.Put "mobile", mobile
usr.Put "telephonenumber", telephonenumber
usr.SetInfo
writeLDAP.MoveNext
loop
response.write "This form has been submitted"
writeLDAP.Close
end if
end if
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCom = Nothing
%>]
The only thing I can think of is that, the login I used wasn't a domain admin account.

Related

One or more errors occurred during processing of command. Provider error '80040e14'

I am getting a Provider error '80040e14' when I do a LIKE on an LDAP query in Classic ASP.
My code is:
<%
response.Buffer = True
function get_ldap_query(firstname, lastname, unit)
dim ADUser, objCom, objCon, objRS
ADUser = "LDAP://OU=Staff,OU=Users,DC=example,DC=internal"
' Make AD connection and run query'
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\test"
objCon.Properties("Password") = "example"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE *" + firstname + "* OR cn like *" + lastname + "*) AND UserAccountControl <> 514 ORDER by cn ASC"
Set objRS = objCom.Execute
Response.Write "<table>" + vbCrLf
Do While Not objRS.EOF Or objRS.BOF
Response.Write " <tr>"
Response.Write "<td>" + objRS("givenName") + "</td>"
Response.Write "<td>" + objRS("sn") + "</td>"
Response.Write "<td>" + objRS("mail") + "</td>"
' Check if field is null to avoid error'
If IsNull(objRS.Fields("Description").Value) Then
sDesc = ""
else
For Each item In objRS.Fields("description").Value
sDesc = item + "<br>"
Next
end if
Response.Write "<td>" + sDesc + "</td>"
Response.Write "<td>" + objRS("mobile") + "</td>"
Response.Write "<td>" + objRS("telephonenumber") + "</td>"
if objRS("sAMAccountName") <> mid(Request.ServerVariables("AUTH_USER"), 11) then
'If the account name held in AD is different to the one the user is logged in with, a blank cell is output. If they are the same, a link allowing the user to edit their entry is displayed'
Response.Write "<td></td>"
else
Response.Write "<td><a href='entry.asp?account_name=" + objRS("sAMAccountName") + "'>Edit</a></td>"
end if
Response.Write "</tr>" + vbCrL
objRS.MoveNext
Response.Flush
Loop
Response.Write "</table>"
'Clean up'
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothin
end function
%>
When this function is called from the index.asp page, which passes the data to the function, I get the error:
Provider error '80040e14'
One or more errors occurred during processing of command.
/pagelets/includes/results.asp, line 19
Which is
Set objRS = objCom.Execute
What am I doing wrong?
The problem is in the below line
objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE *" + firstname + "* OR cn like *" + lastname + "*) AND UserAccountControl <> 514 ORDER by cn ASC"
You are missing single quotes around the firstname and last name, it should look like below.
objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE '*" + firstname + "*' OR cn like '*" + lastname + "*') AND UserAccountControl <> 514 ORDER by cn ASC"
Your code sample also does not show how these are being set, so they could be empty, in which case you get ALL records, in which case you might be returning too many records. You need to add some logic to check if both are these are empty and exit gracefully, or limit the number of records returned somehow.

trying to display other fields from specific access database recordset in asp

I'm new to ASP and have a form that lets users choose a division code from a dropdown box that is populated from an access database. Once they have selected the division, I'd like to be able to collect other fields (name, address, city, state, zip) from that same recordset and pass those fields to another asp page. I'm able to write the selected code to the database, but can't figure out how to collect the other fields from that specific line in the table. My code is
<%
Set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("data/jobdata.mdb")
objconn.Open
Set objRs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM EagleLocations "
objRs.Open strSQL, objconn
Response.Write "<select name=DCode><option value='' selected></option>"
Do While Not objRS.EOF
Response.Write "<option value='" & objrs("DCode") &"'>"& objRs("DCity") &"</option>"
objRS.MoveNext
Loop
Response.Write "</select>"
objRs.Close
objconn.Close
%>
How do I get the page to also get the DName, DAddress1, DAddress2, DCity, DState, and DZIP fields from the selected DCode?
This is my receiving page code where I'm trying to get the data I collected from the form on the previous page to write to a different database:
<%
Dim objconn,strSQL,objRS
Set objconn = Server.CreateObject("ADODB.Connection")
objconn.open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("data/jobdata.mdb")
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL= "SELECT * FROM EagleLocations where Dcode =" & Request.Form("DCode")
objRs.Open strSQL, objconn
DIM strjobstart, strpm, strdcode, strdname, strcustname, strjobsite, strjobsubject, strworkmancompcode
strjobstart = Request.Form("jobstart")
strpmcode = Request.Form("pmcode")
strdcode = Request.Form("dcode")
strdname = Request.Form("dname")
strcustname = Request.Form("listcustname")
strjobsite = Request.Form("listjobsite")
strjobsubject = Request.Form("jobsubject")
strworkmancompcode = Request.Form("workmancompcode")
IF strjobstart <> "" AND strpmcode <> "" AND strdcode <> "" AND strcustname <> "" AND strjobsite <> "" AND strjobsubject <> "" AND strworkmancompcode <> "" THEN
' Process the form as you like here
' For example enter form to your database or send it via email
jobstart = request.form("jobstart")
pmcode = request.form("pmcode")
dcode = request.form("dcode")
dname = request.form("dname")
custname = request.form("listcustname")
jobsite = request.form("listjobsite")
jobsubject = request.form("jobsubject")
workmancompcode = request.form("workmancompcode")
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("data/jobcode.mdb")
strSql = "INSERT INTO JobCodeTemp (jobstart,pmcode,dcode,dname,custname,jobsite,jobsubject,workmancompcode) values( '" & jobstart & "' , '" & pmcode & "' , '" & dcode & "' , '" & dname & "' , '" & custname & "' , '" & jobsite & "' , '" & jobsubject & "' , '" & workmancompcode & "' )"
Cnn.Execute(strSql)
Cnn.Close
Set Cnn = Nothing
'Redirect to the index.asp page
Response.Redirect "display.asp"
csarafin

Line 0 Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done

I have inherited some code old asp/vb code and its throwing an error which I can't find a fix for.
The server is Windows Server 2008, its running IIS7 and the SQL server is 2008.
This is the code:
<% # Language=VBScript %>
<!-- #include file="dsn.asp" -->
<!-- #include file="adovbs.inc" -->
<!-- #include file="libfunct.asp" -->
<%
'****************************************
' VARIABLES DECLARATION
'****************************************
Dim sSql, RsInsCoInfo, PolicyID, InsCo, InsOffice
Dim qsPolicyType, qsAttach, qsCLNT_ID, qsClientID
Dim CostArray(10)
Dim DescriptionArray(10)
'****************************************
' END VARIABLES DECLARATION
'****************************************
'********************************************
' RETRIEVING THE QUERYSTRINGS
'********************************************
qsAttach = Request.QueryString("Attach")
qsCLNT_ID = Request.QueryString("CLNT_ID")
qsClientID = Request.QueryString("ClientID")
qsPolicyType = Request.QueryString("PolicyType")
qsReQuote = Request.QueryString("ReQuote")
qsPolicyID = Request.QueryString("PolicyID")
'********************************************
' END RETRIEVING THE QUERYSTRINGS
'********************************************
'**********************************************
' RETRIEVING THE INSURANCE COMPANY DETAILS
'**********************************************
'Get the insurance company details
Set RsInsCoInfo = Server.CreateObject("ADODB.RecordSet")
sSQL = "SELECT InsuranceCo.*,FormPolicy.* FROM insuranceCo,FormPolicy"
sSQL = sSQL & " WHERE FormPolicy.INS_EF <= CONVERT(smalldatetime,'" & dbSaveDate(Date) & "',101)"
sSQL = sSQL & " And FormPolicy.INS_ET >= convert(smalldatetime,'" & dbSaveDate(Date) & "',101)"
sSQL = sSQL & " AND FormPolicy.PolicyType ='" & qsPolicyType & "'"
sSQL = sSQL & " AND InsuranceCo.INS_ID = FormPolicy.INS_ID"
'response.write ssql
'response.end
RsInsCoInfo.Open sSQL, OLEDBConnStr, adOpenStatic, adLockReadOnly, adCmdText
If Not RsInsCoInfo.EOF then
InsOffice = RsInsCoInfo("INS_Office")
InsCo = RsInsCoInfo("INS_DS")
Else
Response.write "<b>No underwriter available. Please contact the system administrator.<br>"
Response.write sSQL
Response.end
End if
'Close and free
RsInsCoInfo.close
Set RsInsCoInfo = Nothing
'**********************************************
' END RETRIEVING THE INSURANCE COMPANY DETAILS
'**********************************************
'*********************************************************************************
' CLIENT SEQUENCE NUMBER INCREMENT FOR THIS POLICY TYPE
'*********************************************************************************
If Not qsReQuote Then
newPolicyNumber = qsClientID & qsPolicyType
Set RsSequence = Server.CreateObject("ADODB.RecordSet")
sSQL = "SELECT * FROM Policy WHERE PolicyNumber like '%" & newPolicyNumber & "%' AND Clnt_ID=" & qsCLNT_ID
RsSequence.Open sSQL, OLEDBConnStr, adOpenStatic, adLockReadOnly, adCmdText
If RsSequence.recordcount > 0 then
PolicyID = 00
While not RsSequence.eof
If right(RsSequence("PolicyNumber"), 2) > PolicyID then
PolicyID = Cstr(right(RsSequence("PolicyNumber"), 2))
response.write PolicyID & "<br>"
End if
RsSequence.moveNext
Wend
PolicyID = PolicyID + 1
If PolicyID < 10 then
PolicyID = "0" & CStr(PolicyID)
End If
Else
PolicyID = "01"
End If
RsSequence.close
SET RsSequence = NOTHING
End If
'*********************************************************************************
' END CLIENT SEQUENCE NUMBER INCREMENT FOR THIS POLICY TYPE
'*********************************************************************************
'*********************************************************************************
' UPDATING ADDITIONNAL FIELD TO THE QUOTE CREATION
'*********************************************************************************
'Setting var
Dim strConnection, SQL_Upsate, newPolicyNumber
newPolicyNumber = qsClientID & qsPolicyType & PolicyID
If Not qsReQuote Then
'Insert Sql Statement
SQL_Update = "UPDATE Policy SET CLNT_ID=" & qsCLNT_ID & ","
SQL_Update = SQL_Update & " InsuranceCo='"& InsCo & "',"
SQL_Update = SQL_Update & " Office='"& InsOffice & "',"
SQL_Update = SQL_Update & " StatusID="& 0 & ","
SQL_Update = SQL_Update & " PolicyNumber='" & newPolicyNumber & "'"
SQL_Update = SQL_Update & " WHERE PolicyID=" & qsAttach
Else
'Insert Sql Statement
SQL_Update = "UPDATE Policy SET CLNT_ID=" & qsCLNT_ID & ","
SQL_Update = SQL_Update & " InsuranceCo='"& InsCo & "',"
SQL_Update = SQL_Update & " Office='"& InsOffice & "',"
SQL_Update = SQL_Update & " StatusID="& 0
SQL_Update = SQL_Update & " WHERE PolicyID=" & qsPolicyID
End If
'Connection object and open the db
Set strConnection = Server.CreateObject("ADODB.Connection")
strConnection.Open OLEDBConnStr
' Executing the sql insert
strConnection.Execute SQL_Update
'Now Close the connection and free up
strConnection.Close
Set strConnection = Nothing
'*********************************************************************************
' END ADDING ADDITIONAL FIELDS TO THE QUOTE CREATION
'*********************************************************************************
'*********************************************************************************
' DO CALCULATION
' - obtains file named Policy & 'Calculations.inc' = HHCalculations.inc etc.
'
' Modified by Stuart 20/5/03
'*********************************************************************************
set Rs = Server.CreateObject("ADODB.Recordset")
If Not qsReQuote Then
sSQL = "SELECT Policy.* FROM Policy WHERE Policy.PolicyID=" & qsAttach
Else
sSQL = "SELECT Policy.* FROM Policy WHERE Policy.PolicyID=" & qsPolicyID
End If
Rs.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
'********************************************
'Response.write "<B>Policy table For Testing Only<P></b>"
'For Each fld in Rs.fields
' Response.write fld.name & " = " & fld.value & "<br>"
'Next
'Response.end
'**********************************************
Agent = 0
Agent2 = 0
AgentIntro = 0
'Open rsAccount for writing account entries to the PolicyAmount table
'** Comment derek to Stuart -> wont we be better here to find the agent with the code?
If Session("Agent") <> "" then
set RsAgent = Server.CreateObject("ADODB.Recordset")
sSQL = "Select * from Agents Where Name = '" & Session("Agent") & "'"
RsAgent.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
Agent = rsAgent("commission")
End if
'If a park was involved for a new business then the introductory rate is required.
If Session("Village_Name") <> "" then
set RsPark = Server.CreateObject("ADODB.Recordset")
If IsNumeric(Session("Village_Name")) Then
sSQL = "Select * from Park Where ParkID = '" & Session("Village_Name") & "'"
Else
sSQL = "Select * from Park Where ParkID = '" & Session("reParkID") & "'"
End If
RsPark.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
If RsPark.eof then
Response.write "<b>" & ssql & "<P>No Park record found - Line 189 QuoteSave2.asp<P>Please contact you system administrator."
'Response.end
Else
AgentIntro = RsPark("Introduction")
End if
End if
set RsAccount = Server.CreateObject("ADODB.Recordset")
set RsQuestions = Server.CreateObject("ADODB.Recordset")
If Not qsReQuote Then
sSQL = "SELECT * FROM PolicyAmount WHERE PolicyID=" & qsAttach
Else
sSQL = "SELECT * FROM PolicyAmount WHERE PolicyID=" & qsPolicyID
End If
RsAccount.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
If Not qsReQuote Then
sSQL = "SELECT * FROM PolicyQuestions WHERE PolicyID=" & qsAttach
Else
sSQL = "SELECT * FROM PolicyQuestions WHERE PolicyID=" & qsPolicyID
End If
RsQuestions.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
If Not qsRequote Then
RsAccount.Addnew
End If
If Not qsRequote Then
RsAccount("PolicyID") = qsAttach
linkID = qsAttach
Else
RsAccount("PolicyID") = qsPolicyID
linkID = qsPolicyID
End If
sTargetFile = qsPolicyType & "Calculations.inc"
sTargetFileContents = GetFileContentsForExecution(sTargetFile)
Execute sTargetFileContents
'*********************************************************************************
' END DO CALCULATION
'*********************************************************************************
'*********************************************************************************
' WRITE COSTS TO THE TABLE
'*********************************************************************************
'Update data to the PolicyAmount table
RsAccount("PolicyAmount_IB") = Session("Login")
RsAccount("PolicyAmount_IT") = Date
RsAccount.Update
'**********************************************
'Response.write "<P><B>PolicyAmount table For Testing Only<P></b>"
'For Each fld in RsAccount.fields
' Response.write fld.name & " = " & fld.value & "<br>"
'Next
'Response.write "<P><B><a href='default.asp'>Home</a>"
'Response.end
'***********************************************
'Clean up
RsAccount.Close
Set RsAccount = Nothing
Rs.update
Rs.Close
Set Rs = Nothing
RsQuestions.Close
Set RsQuestions = Nothing
'RsPark.close
'Set RsPark = Nothing
'Finish with this second saving so redirect to the policy page
If Not qsReQuote Then
Response.redirect "Policy.asp?PolicyID=" & qsAttach & "&CLNT_ID=" & qsCLNT_ID & "&ClientID=" & qsClientID & "&PolicyType=" & qsPolicyType
Else
Response.redirect "Policy.asp?PolicyID=" & qsPolicyID & "&CLNT_ID=" & qsCLNT_ID & "&ClientID=" & qsClientID & "&PolicyType=" & qsPolicyType
End If
%>
This is the error: "Warning: File /quotesave2.asp Line 0 Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.. ."
It really doesn't give me much to go on and any help/insight would be greatly appreciated.
Thanks.
It's real tough to pin down the exact issue with no line number. I noticed towards the end of the script, you are adding a new record to RsAccount and assigning values to the recordset fields. In the past, I have gotten the "Multiple-step OLE DB operation generated errors" error due to type mismatches between the VBScript variable and the recordset field type. Double-check the data type of the columns that you are updating, and if necessary, explicitly convert values before assigning them to the recordset (for example, using CLng for numbers).
This is classic, i handle these problems by logging each command to the db just before executing. So eg
log(sSql)
RsAccount.Open sSQL, OLEDBConnStr, adOpenkeyset, adLockPessimistic, adCmdText
Where log(tekst) is a sub which writes to a txt file the passed text. Now when you encounter an error execution stops and you check your log. The last entry is the sql generating the error. Execute this sql in an interactive environment where you can easily adjust the text and try again and where you get more accurate error from your dbclient. Don't know what it is for Sql Server, i use Oracle and there it is Sql*Plus, i'm sure there must be others for Sql Server. Once you corrected your sql, paste it in your code, replacing your literals with variables. Request your page again and do the above until all your sql is correct.
First, your SELECT statement is selecting multiple field with same name which might cause a problem. Change your statement to this: (You might need to change the table of INS_DS, I just guessed)
sSQL = "SELECT ic.INS_Office, fp.INS_DS "&_
"FROM insuranceCo ic INNER JOIN FormPolicy fp ON ic.INS_ID = fp.INS_ID "&_
"WHERE fp.INS_EF <= CONVERT(smalldatetime,'" & dbSaveDate(Date) & "',101) "&_
"AND fp.INS_ET >= convert(smalldatetime,'" & dbSaveDate(Date) & "',101) "&_
"AND fp.PolicyType = '" & qsPolicyType & "'"
If still same error, I remember getting this one when messing around with Date/Time fields so those two date fields are suspects. For sake of debug try to select without that filter and see what happens:
sSQL = "SELECT ic.INS_Office, fp.INS_DS "&_
"FROM insuranceCo ic INNER JOIN FormPolicy fp ON ic.INS_ID = fp.INS_ID "&_
"WHERE fp.PolicyType = '" & qsPolicyType & "'"

unable to execute query in ASP

Following is the ASP code that I am working on:
Dim sConnString, connection, sSQL, backgroundColor
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
sConnString=//a connection string
Set connection = Server.CreateObject("ADODB.Connection")
connection.Mode=adModeRead
connection.Open(sConnString)
connection.execute(sSQL)
Response.Write"<table>"
do while not connection.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write"<tr backgroundColor="& backgroundColor & "></td>" & connection("firstName") & "</td><td>" & connection("lastName") & "</td><td>" & connection("email") & "</td><td>" & connection("zip") & "</td><td>" & connection("country") & "</td><td>" & connection("company") & "</td><td>" & connection("industry") & "</td><td>" & connection("revenue") & "</td><td>" & connection("timestamp") & "</td></tr>"
connection.MoveNext
Loop
Response.Write"</table>"
connection.Close
Set connection = Nothing
I am getting the following error:
ADODB.Connection error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/wsu.asp, line 13
Line 13:
do while not connection.EOF
Could you please help me with this?
Updated code:
<html>
<body>
<%
Dim sConnString, connection, sSQL, backgroundColor
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
sConnString="a connection string for MS SQL database;"
Set connection = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
connection.Mode=adModeRead
rs.open sSQL,connection
Response.Write"<table>"
do while not connection.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write "<tr backgroundColor="& backgroundColor & "></td>" & connection("firstName") & "</td><td>" & connection("lastName") & "</td><td>" & connection("email") & "</td><td>" & connection("zip") & "</td><td>" & connection("country") & "</td><td>" & connection("company") & "</td><td>" & connection("industry") & "</td><td>" & connection("revenue") & "</td><td>" & connection("timestamp") & "</td></tr>"
connection.MoveNext
Loop
Response.Write"</table>"
connection.Close
Set connection = Nothing
%>
</body>
</html>
See the following edit in your code -
you create a recordset and then open it and execute it
<html>
<body>
<%
Dim sConnString, connection, sSQL, backgroundColor,objrs
sSQL = "SELECT firstName, lastName, email, zip, country, company, industry, revenue, timestamp FROM users"
Set connection = Server.CreateObject("ADODB.Connection")
connection.connectionstring = "put your connection string in here"
' replace put your connection string in here with your connection string
Set objrs= Server.CreateObject("ADODB.Recordset")
connection.Open()
objrs.open sSQL,connection
Response.Write"<table>"
do while not objrs.EOF
if(backgroundColor="#f1f1f1")then
backgroundColor="#ffffff"
else
backgroundColor="#f1f1f1"
end if
response.write"<tr backgroundColor="& backgroundColor & "></td>" & objrs("firstName") & "</td><td>" & objrs("lastName") & "</td><td>" & objrs("email") & "</td><td>" & objrs("zip") & "</td><td>" & objrs("country") & "</td><td>" & objrs("company") & "</td><td>" & objrs("industry") & "</td><td>" & objrs("revenue") & "</td><td>" & objrs("timestamp") & "</td></tr>"
objrs.MoveNext
Loop
Response.Write"</table>"
%>
</body>
</html>
a note:--
this needs to be something like - not sure what database you are using -
sConnString= "Provider=sqloledb;Data Source=ServerName;Initial Catalog=DatebaseName "
or if you have a dsn connection then simply
sConnString = "DSN=xxxxx;uid=xxx;pwd=xxx"
You will need to create a Recordset to read the data from your SQL query. You have used connection itself.
try below example.
HERE

putting values from database into a drop down list

my tool is in asp. i am using this code for a query in sql
dim req_id
req_id=Request.Form("Req_id")
if req_id<>"" then
Set conn=server.CreateObject("adodb.connection")
conn.Open session("Psrconnect")
Set rs=CreateObject("Adodb.Recordset")
rs.Open "select * from passwords where REQ_ID='"&req_id&"'", conn
i want to put the results of this query into a drop down list. how do i do it? any help is very much appreciated.
Slightly edited code from my working pages :
function HtmlFormOption( byval psReturnValue, byval psDisplayValue ,byval psCurrentDefault)
dim x
if IsNull(psCurrentDefault) then psCurrentDefault = ""
if IsNull(psReturnValue) then psReturnValue = ""
if lCase( cStr(psReturnValue) ) = lCase( cStr(psCurrentDefault)) then
x = "selected "
else
x = ""
end if
HtmlFormOption = "<option " & x & "value='" & psReturnValue & "'>" & psDisplayValue & "</option>"
end function
dim Result, sCode, sWaarde
Result = "<select name='NameCombobox' size='1'>" & vbCrlf
while not objRecLookup.Eof
sCode = objRecLookup.Fields(0) ' first field in result set
sWaarde = objRecLookup.Fields(1) ' second field in result set
if not IsNull(sCode) and not IsNull(sWaarde) then
Result = Result & HtmlFormOption( sCode, sWaarde , psCurrentDft )
end if
objRecLookup.MoveNext
wend
objRecLookup.Close
Result = Result & "</select>" & vbCrlf
And than Response.Write(Result)
Here's a simple solution:
<%
Dim objCommand, objRS
Set objCommand = Server.CreateObject("ADODB.Command")
with objCommand
.ActiveConnection = objConn
.CommandType = adCmdText
.CommandText = "SELECT * FROM PASSWORDS WHERE REQ_ID= '" & req_id & "'"
Set objRS = .Execute
end with
%><select name="selectbox"><%
While NOT objRS.EOF
%><option value="<%=objRS("COLUMN_NAME")%>"><%=objRS("COLUMN_NAME")%></option><%
objRS.MoveNext
Wend
%></select><%
objRS.Close
Set objRS = Nothing
Set objCommand = Nothing
%>

Resources