Note that there are some explanatory texts on larger screens.

plurals
  1. POADODB Command failing Execute with parameterised SQL query
    primarykey
    data
    text
    <p>I have the following JScript code:</p> <pre><code>var conn = new ActiveXObject ("ADODB.Connection"); conn.Open("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=blah_blah_blah;User=foo;Password=bar;"); var cmd = new ActiveXObject("ADODB.Command"); cmd.ActiveConnection = conn; var strSQL = "SELECT id FROM tbl_info WHERE title LIKE :search ORDER BY id"; var search = "test"; try{ cmd.CommandText = strSQL; var param = cmd.CreateParameter(':search', 200, 1, 100, search); cmd.Parameters.Append(param); var rs = cmd.Execute(); } catch (ex) { Application.Alert("Error retrieving id information from database."); } </code></pre> <p>I've verified (by printing them) that the Connection object is set to be the Command's ActiveConnection, the parameter object has the correct value and the Command object has the correct SQL query as its CommandText. I also inserted an alert statement after each line in the try block to see where the error was occuring - it's fine after cmd.Parameters.Append but the exception gets thrown upon running the Execute statement.</p> <p>I've tried displaying the actual exception but it's just a generic 'Object error' message.</p> <p>The query executes fine and returns the correct result set when I just execute the SQL query (without the parameter) straight through the Connection object, but seems to fail when I use a parameterised query with the Command object.</p> <p>As far as I can see all settings and properties of the Command and Connection objects are correct but for whatever reason it's throwing an exception.</p> <p>Any help with this would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload