I get this error when I try to start a Stored Procedure through pyodbc in an SQL Server database with a TVP and a column has a None value.
[HY004] [Microsoft][ODBC Driver 18 for SQL Server]Invalid SQL data type (0) (SQLBindParameter)
Is there any way to indicate to pyodbc the datatype of the column or do I have to give up in TVP's?
This is what I'm trying:
cursor.execute("{CALL dbo.stored_procedure (?, ?)}", (None, tvp_data))
First variable I don't care about, second one is my TVP. Everything works fine as long as there is no None in a column in the TVP itself, but if there is, I get the error.
This is a known limitation of the parameter metadata discovery as discussed on GitHub here and here. Workarounds include:
Option 1. Sort your TVP data so the first row contains no
Nonevalues.Option 2. Use
OPENJSON()in an anonymous code block and pass your TVP data as a JSON string.(Example copied from my own GitHub comment here.)