import pyodbc
import numpy
import pandas as pd
import pypyodbc
def sql_conn():
conn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};"
"Server=;"
"Database=db_name;"
"uid=xxxx;pwd=xxxx;")
cursor = conn.cursor()
cursor.execute('SELECT * FROM dbo.ImageDB')
for row in cursor:
print(row)
It's running on a Windows Server 2012 R2.
Whenever I run the python script I keep getting the message
Process finished with exit code 0
I know the connection wasn't made. How do I get the server name? Is it a combination of the server IP and the SQL Server name? Do I need to provide a PORT number? I tried a bunch of combinations for the server name but all give me the same output.
Also which is better pyodbc or pypyodbc?
I am sorry if this sounds like a stupid question but I am really new to this and any help would be appreciated.
Thanks.