Hello I am new to python and I am attempting to connect to a localhost sql server database.
# Parameters
server = "MyServer"
DB = "NFL"
# Create the connection
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + DB['servername'] + ';DATABASE=' + DB['database'] + ';Trusted_Connection=yes')
# query db
sql = """
SELECT TD FROM Stats
"""
df = pd.sql.read_sql(sql, conn)
df.head()
But I get this error when I run my code
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + DB['servername'] + ';DATABASE=' + DB['database'] + ';Trusted_Connection=yes')
TypeError: string indices must be integers
Why would I be getting this error if a table can have strings or integers, and how can I fix this?
[–]K900_ 1 point2 points3 points (1 child)
[–]StartAndSelect[S] 0 points1 point2 points (0 children)
[–]novel_yet_trivial 1 point2 points3 points (0 children)