DB::Exception: Query parameter `Parameter Name` was not set (version 19.17.3.7 (official build))
I've successfully built a driver for windows and try to use it from powershell. I've wrote small script:
$DbConnection = new-object System.Data.Odbc.OdbcConnection("DSN=ss");
$DbConnection.Open();
$DbCommand = $DbConnection.CreateCommand();
$DbCommand.CommandText = "INSERT INTO DisplayToID (NumberOfRecords, DisplayString) VALUES (@NumberOfRecords,'test1')";
$DbCommand.Parameters.Add("@NumberOfRecords", [System.Data.Odbc.OdbcType]::SmallInt).Value = 10;
$DbCommand.ExecuteReader();
and when i try to run it then receive following error:
Exception calling "ExecuteReader" with "0" argument(s): "ERROR [HY000] HTTP status code: 500
Received error:
Code: 456, e.displayText() = DB::Exception: Query parameter NumberOfRecords was not set (version 19.17.3.7 (official build))
"
At C:\PSWEB\Untitled4.ps1:10 char:1
- $DbCommand.ExecuteReader();
-
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : OdbcException
Can I use parameters in my queries?
The body of http request is:
INSERT INTO DisplayToID (NumberOfRecords, DisplayString) VALUES ({NumberOfRecords:Nullable(Int16)},'test1')
As you can see it not contain a value of parameter NumberOfRecords (should be 10)
Could you please attach a fully standalone reproducible case. I don't think named parameters will work as you expect. To some extent driver will be able to process them, but not in all cases. If you attach a standalone script and instructions how to run it, I'll try to see what's happening there, and whether that could be fixed, or is just something that hits the limitations of ODBC.
Also, take a look at this: https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/binding-parameters-by-name-named-parameters and probably this https://stackoverflow.com/a/8194706/837811