I am completely new to PyCharm and I'm having the hardest time trying to figure out the PyCharm equivalent of running a SQL query in Jupyter Notebook using pyodbc. My ultimate goal is to run a very simple query and save the result table in a df within my python code in PyCharm. I have my PyCharm environment connected to my database, and I can see the SQL table I want to query when I click the Database explorer icon on the right side of the screen in PyCharm. However, when I go to use pyodbc to connect to the database and run my query, I get this error:
pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Cannot generate SSPI context (0) (SQLDriverConnect); [HY000] [Microsoft][ODBC SQL Server Driver]Cannot generate SSPI context (0)')
The code that generates this error is
conn = pyodbc.connect('Driver={SQL Server};'
'Server=[server name], [port name];'
'Database=[db name];'
'Trusted_Connection=yes;')
cursor = conn.cursor()
SQLstr = """
select *
from ETLStaging.dbo.Advisor
"""
advisordf = pandas.read_sql(SQLstr, conn)
advisordf
Well, more specifically it's the very first line of code that throws the error. I'm just at a loss here and I'm not sure if I'm even barking up the right tree because all of the JetBrains (PyCharm) documentation I've read seems to indicate that there's an easier way to run a SQL query in PyCharm without having to write the connection string for pyodbc. I've searched and searched but I keep finding forums and articles that refer me to other forums and articles. I can view the SQL table I want to query in the database explorer in PyCharm, but I don't know how to get it into a dataframe in my code. Do I just need to fix my connection string? Or am I going about this the completely wrong way?
Really appreciate any guidance anyone might be able to give here!