paul_noden
asked on
Struggling to resolve ADO ASP error for SQL Server 2008 and IIS7
Trying to convert a number of queries from dynamic sql to parameterised sql. The query used works as a dynamic sql statement, but with parameters I am getting:
ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict
with one another.
conn.errors.count shows 0
ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict
with one another.
conn.errors.count shows 0
SQL = "UPDATE tblListings SET userSynopsis = '" & userSynopsis & "' WHERE ListingID = " & ListingID & ";"
Set DataConnection = Server.CreateObject("ADODB.Connection")
strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
strconn=strconn & DatabasePathString
DataConnection.Open SQLstrDataConnectionString
'dataconnection.Execute SQL
Set Cmd1 = CreateObject("ADODB.Command")
Set Param1 = CreateObject("ADODB.Parameter")
Set Param2 = CreateObject("ADODB.Parameter")
Set Rs1 = CreateObject("ADODB.Recordset")
Cmd1.ActiveConnection = DataConnection
Cmd1.CommandText = "UPDATE tblListings SET userSynopsis = '?' WHERE ListingID = ?;"
Set Param1 = Cmd1.CreateParameter("@userSynopsis", adVarWChar, adParamInput, 250,CStr(userSynopsis))
Cmd1.Parameters.Append Param1
Set Param2 = Cmd1.CreateParameter("@ListingID", adSmallInt, adParamInput, 4,CInt(ListingID))
Cmd1.Parameters.Append Param2
Set Param1 = Nothing
Set Param2 = Nothing
' Open Recordset Object.
'Set Rs1 =
Cmd1.Execute()
DataConnection.Close
Set DataConnection = Nothing
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for that, I had started with adInteger but must have forgot to put back the correct ado type after testing other types.
Set Param1 = Cmd1.CreateParameter(, adVarWChar, adParamInput, 250, CStr(userSynopsis))
is the first parameter to be reported as problematic.
Which is of course supposed to be the correct type.. Any thoughts?
Set Param1 = Cmd1.CreateParameter(, adVarWChar, adParamInput, 250, CStr(userSynopsis))
is the first parameter to be reported as problematic.
Which is of course supposed to be the correct type.. Any thoughts?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On what you posted originally you have:
DataConnection.Open SQLstrDataConnectionString
but your connection string is stored in the variable:
strconn
NOT SQLstrDataConnectionString .
>>also I needed ...
I didn't realize you didn't have that already. Since you were using many constants all over, it was logical to assume you had them defined somewhere (either via the METADATA OR via the tradional adovb.inc file)
Lastly, on the sql statements, the question marks should not have apostrophes around them, even if the value is a string. Below is a sample code that worked for me
DataConnection.Open SQLstrDataConnectionString
but your connection string is stored in the variable:
strconn
NOT SQLstrDataConnectionString
>>also I needed ...
I didn't realize you didn't have that already. Since you were using many constants all over, it was logical to assume you had them defined somewhere (either via the METADATA OR via the tradional adovb.inc file)
Lastly, on the sql statements, the question marks should not have apostrophes around them, even if the value is a string. Below is a sample code that worked for me
Set DataConnection = Server.CreateObject("ADODB.Connection")
strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
strconn=strconn & DatabasePathString
DataConnection.Open strconn 'SQLstrDataConnectionString
'dataconnection.Execute SQL
Const adVarWChar=202
Const adParamInput=1
Const adInteger=3
Set Cmd1 = CreateObject("ADODB.Command")
Set Param1 = CreateObject("ADODB.Parameter")
Set Param2 = CreateObject("ADODB.Parameter")
Set Rs1 = CreateObject("ADODB.Recordset")
Cmd1.ActiveConnection = DataConnection
' Cmd1.CommandText = "UPDATE tblListings SET userSynopsis = '?' WHERE ListingID = ?;"
'do not put apostrophes around the question marks
Cmd1.CommandText = "UPDATE [Inserts] SET Email = ? WHERE ID = ?;"
' Set Param1 = Cmd1.CreateParameter("@userSynopsis", adVarWChar, adParamInput, 250,CStr(userSynopsis))
Set Param1 = Cmd1.CreateParameter("@Email", adVarWChar, adParamInput, 250,"test_12999@fake.domain.com")
Cmd1.Parameters.Append Param1
' Set Param2 = Cmd1.CreateParameter("@ListingID", adSmallInt, adParamInput, 4,CInt(ListingID))
Set Param2 = Cmd1.CreateParameter("@ID", adInteger, adParamInput, 4,425)
Cmd1.Parameters.Append Param2
Response.Write Cmd1.CommandText
' Open Recordset Object.
'Set Rs1 =
Cmd1.Execute()
Set Param1 = Nothing
Set Param2 = Nothing
Notice that I commented out some of your original statements
On my last post I forgot to mention that since you are already using the METADATA, you won't need these definitions:
Const adVarWChar=202
Const adParamInput=1
Const adInteger=3
Const adVarWChar=202
Const adParamInput=1
Const adInteger=3
ASKER
Yes, this code was someone else's that I'm trying to overhaul (there's some serious issues with the approaches taken) and apparently defining their own constants was part of the fun. Changing from an access database to SQL Server and leaving the remnants of the access file lying all over the code is another as you've now spotted. It's using the correct connection, the strconn lines appear to be defunct.
"on the sql statements, the question marks should not have apostrophes around them, even if the value is a string" good to know, I've seen MSDN articles use both mechanisms when researching for my solution.
"on the sql statements, the question marks should not have apostrophes around them, even if the value is a string" good to know, I've seen MSDN articles use both mechanisms when researching for my solution.
ASKER
Open in new window