0

I cannot get Python Turbodbc to connect to a Sql Server table, simple as that seems, to read or write user tables. However I have established ODBC connection, and can print a list of objects from it.

1 List objects from server to test connection. Seems to work:

from turbodbc import connect, make_options
options = make_options(prefer_unicode=True)
connection = connect(dsn='FPA', turbodbc_options=options)
cursor = connection.cursor()
cursor.execute('''SELECT * FROM sys.objects WHERE schema_id = SCHEMA_ID('dbo');''')

2 Simple Select: Does not work

cursor.execute('''SELECT * from [dbo].[Kits_Rec];''')    

From #1 I get

From # 2 message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'dbo.Kits_Rec'.

enter image description here

Community
  • 1
  • 1
Brad Clay
  • 1
  • 3

1 Answers1

0

A SQL Server contains multiple databases, your dsn "FPA" probably doesn't specify the database name, so you are connecting to the master database instead of the database containing your Kits_Rec table.

Fix that dsn entry to specify the correct database, or use this syntax instead :

connection = connect(driver="MSSQL Driver",
                     server="hostname",
                     port="1433",
                     database="myDataBase",
                     uid="myUsername",
                     pwd="myPassword")
Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
  • I tried the specs above, but since I am using an integrated windows connection, I could not populate the credentials info. So I fixed the dsn, as you suggested, and that did the trick! I am very grateful, and a little embarrassed that never occured to me. thank you – Brad Clay Jul 18 '19 at 18:02