Question

FYI DB=database_Streaming_Service_GoFlix; I am running the following script to connect through python: =========================================================== import pyodbc conn...

FYI

DB=database_Streaming_Service_GoFlix;

I am running the following script to connect through python:

===========================================================

import pyodbc

conn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};"
                      "Server=test;"
                      "Database=database_Streaming_Service_GoFlix;"
                      "Trusted_Connection=yes;")

cursor = conn.cursor()
cursor.execute('SELECT * FROM database_Streaming_Service_GoFlix')

for row in cursor:
    print('row = %r' % (row,))

========================================

Output:

Traceback (most recent call last):
File "C:\Users\test\AppData\Local\Programs\Python\Python39\Scripts\db_connect.py", line 10, in <module>
    cursor.execute('SELECT * FROM database_Streaming_Service_GoFlix')
pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'database_Streaming_Service_GoFlix'. (208) (SQLExecDirectW)")

=====================================================

not sure if this has to do with the odbc driver installation?

However, when I run following script:

======================================================
import pyodbc

conn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};"
"Server=test;"
"Database=database_Streaming_Service_GoFlix;"
"Trusted_Connection=yes;")


cursor = conn.cursor()
cursor.execute('SELECT * FROM dbo.customer')

for row in cursor:
print('row = %r' % (row,))
===============================================
Output:

row = (102, 'Aron ', None, None, None)
row = (108, 'Bon ', '9327870817', '[email protected]', 'Plaza drive 20011, CA')
row = (109, 'Don ', '123335666', '[email protected]', 'Plaza drive 200352, CA')
row = (112, 'Ben ', '13345666', '[email protected]', 'Plaza drive 23300, CA')
row = (1033, 'Ron ', '12345666', '[email protected]', 'Plaza drive 200, CA')
row = (1234, 'John ', '1234567890', '[email protected]', '65 Plaza Ave, Suite 200,')
row = (4565, 'Alan ', '1234567890', '[email protected]', '35 Sun St, floor 2 ')
row = (7896, 'David ', '1234567890', '[email protected]', '222 longbeach ave, ')
row = (101112, 'Thomas ', '1234567890', '[email protected]', '47 broadway st, suite30')
row = (121415, None, '1234567890', None, '723 W 19th')
=========================================================================
I am not sure why (SELECT *) syntax is not running but when I use dbo.Table_name it works.

Do you think its still related to the pyodbc driver?

thanks,

Homework Answers

Answer #1

the error that you are getting can be due to the fact that you can not using the authentication means for establishing the connection with the database so try using authentication means for connecting to the database and the error invalid object name comes when you are trying to update data in a disconnected database. Try using authentication methods to verify the connection to the database. And another step that you need to follow is to to verify the odbc version and you need to look for the odbc and verified the odbc is there and if it is there then you need to upgrade it or download it from the internet.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT