Forum Discussion

NisHera's avatar
NisHera
Valued Contributor
8 years ago
Solved

Python SQLServer Query -IDispatchIndexedPropertyWrapper' object is not callable

I have following query (allmost same as in support site)

def TestSQL_ADO2():
  # Creates ADO connection
  aCon = ADO.CreateConnection()
  # Sets up the connection parameters
  #aCon.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=NameOfMyDSN"
  aCon.ConnectionString = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=LocalMachine\SQLEXPRESS2012'
  # Opens the connection
  aCon.Open()
  # Creates a command and specifies its parameters
  aCmd = ADO.CreateCommand()
  aCmd.ActiveConnection = aCon # Connection
  aCmd.CommandType = adCmdTable # Command type
  aCmd.CommandText = "titles_tab" # Table name
  # Opens a recordset
  aRecSet = aCmd.Execute()
  aRecSet.MoveFirst()
  # Obtains field names
  s = ""
  for i in range (0, aRecSet.Fields.Count):
    s = s + aRecSet.Fields.Item(i).Name + "\t"
  s = s + "\r\n"
  # Scans recordset
  while not aRecSet.EOF:
    for i in range (0, aRecSet.Fields.Count):
      s = s + aRecSet.Fields.Item(i).Value + "\t"
    s = s + "\r\n"
    aRecSet.MoveNext()
  # Outputs results
  Log.Message("Products", s)
  # Closes the recordset and connection
  aRecSet.Close()
  aCon.Close()

Gives me error 

TypeError
'IDispatchIndexedPropertyWrapper' object is not callable
Error location:
Unit: "..........t\Test"
Line: 61 Column: 1.

which is the line

s = s + aRecSet.Fields.Item(i).Name + "\t"

If I comment reading ADO record set and taking only counts like below

 p = 0
  for i in range (0, aRecSet.Fields.Count):
    #s = s + aRecSet.Fields.Item(i).Name + "\t"
    Log.Message(aRecSet.Fields.Count)
  #s = s + "\r\n"
  # Scans recordset
  while not aRecSet.EOF:
    for i in range (0, aRecSet.Fields.Count):
      p = p+1
      Log.Message(str(p))
      #s = s + aRecSet.Fields.Item(i).Value + "\t"
    #s = s + "\r\n"
    aRecSet.MoveNext()

Gives me correct number of columns and rows.....which I guess DB connection is OK

 

What am I doing wrong? or is it a bug?

The code I'm running is exact same at hear except connection string

I'm running TC 12.1..5..

2 Replies