0

I want to call a MSSQL Stored Procedure from Python which takes table value as a parameter, and which was earlier triggered from API by passing  

{
  "data": 
        [{"xyz": 340, "abc": 0, "ijk": '296202302M13', 
          "files": [{
                     "pfile": 'xyz.txt',
                     "fName": 'abc.txt',
                     "fileDate": '2023-02-28 23:25:03.000'}]
                   }]
}

 

This calls the stored procedure by storing this JSON into table value parameter and passes it to the SP.

I have tried using pytds library to pass table value parameter and to call the stored procedure but I am getting the error as:

Unable to determine database type from python TableValuedParam type

If I try to call the procedure by passing as a list then getting the same error

Unable to determine database type from python List type

 

I am using callproc() to call the stored procedure.

Edit: Python code

mydb = db_connection(server, username, password, database) cursor = mydb.cursor() 

file = ['test1.txt', 'test2.txt', '2023-02-28 23:25:03.000'] 
my_tvp = ['444', '0' , '20230327XYZ', file] 

tvp = pytds.TableValuedParam(type_name='FileListType', rows=my_tvp) 

param = (tvp,) 
cursor.callproc('test1', param)

This is the part of SP which might be useful

ALTER PROCEDURE [dbo].[test1] (
    @FileList FileListType Readonly

    ,@ReturnMessage VARCHAR(1000) = '' OUTPUT
)
9
  • stackoverflow.com/q/51930062/61305 Commented Mar 27, 2023 at 9:56
  • Hi Aaron, I tried the prescribed method but I am getting the "Unable to determine database type from python TableValuedParam type" when I tried with pytds I have to pass the above json to the stored procedure Commented Mar 27, 2023 at 11:35
  • 1
    Show us your actual Python code. Commented Mar 27, 2023 at 11:39
  • We can't help you troubleshoot what we can't see. Why haven't you posted the actual code you're trying? Commented Mar 27, 2023 at 12:04
  • Hi, Aaron and Thom I have edited my actual code Thanks for the changes, This is actually my first question Commented Mar 27, 2023 at 12:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.