PratikShah111
asked on
Connect to sql server using Python
I am just writing a simple python script to connect to sql server . SQL server that I am trying to connect does not have trusted connection and so i have to login using integrated authentication. so in my script i try to login using the username and password that i use to login into management studio. but when i execute the script it gives me an error message saying login failed for user "it shows my windows username" and just ignores the username that I am passing in my script.
Below is my script.
server = "xxxxxxx.svr.us.xxxxxx.net \\Serverna me"
database = "MyDatabase"
username = "username"
password = "password"
con = pyodbc.connect('DRIVER={SQ L Server};Server='+server+'; Database=' +database+ ';username ='+usernam e+';passwo rd='+passw ord)
print (con)
con = conStr
cur = con.cursor() #Generates error on this line
cur.execute("SELECT top 10 * from mytable;")
error that i get
pyodbc.Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'OVER HERE I SEE MY WINDOWS USERNAME. (18456) (SQLDriverConnect)")
Below is my script.
server = "xxxxxxx.svr.us.xxxxxx.net
database = "MyDatabase"
username = "username"
password = "password"
con = pyodbc.connect('DRIVER={SQ
print (con)
con = conStr
cur = con.cursor() #Generates error on this line
cur.execute("SELECT top 10 * from mytable;")
error that i get
pyodbc.Error: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'OVER HERE I SEE MY WINDOWS USERNAME. (18456) (SQLDriverConnect)")
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Initiating auto close as we haven't heard back from author and solution provided..
ASKER