I'm trying to connect to it from another domain with this code below but I'm getting an error like this
InterfaceError: (pyodbc.InterfaceError) ('28000', '[28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. (18452) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. (18452)') (Background on this error at: http://sqlalche.me/e/13/rvf5)
This is my code that I'm using:
import pyodbc
from sqlalchemy import create_engine
server = 'shul'
database = 'db_pre'
uid = 'pre'
pwd = 'pr@20si'
engine = create_engine('mssql+pyodbc://' + server + '/' + database + '/' + uid + '/' + pwd + '?trusted_connection=no&driver=ODBC+Driver+13+for+SQL+Server')
#engine = create_engine('mysql://root:@localhost/daming') # enter your password and database names here
col_names = ["month", "price", "change"]
df = pd.read_csv("kcl.csv",sep=',',quotechar='\'',encoding='utf8', names=col_names,skiprows = 1) # Replace Excel_file_name with your excel sheet name
df.to_sql('kcl',con=engine,index=False,if_exists='replace') # Replace Table_name with your sql table name
In SQL Server Management Studio I used SQL Server authentication instead of Windows Authentication.
Please help me. Thank you in advance.
server,database,uidandpwddoesn't look correct. I've put it in an f-string to try make it clearer.f'mssql+pyodbc://{uid}:{pid}@{server}/{database}?driver=ODBC+Driver+13+for+SQL+Server;Trusted_Connection=no'- PGHE@in your password. If that is in your password it'll cause problems. - PGHE@or/or#. It's quite likely that an unexpected character made SQL Alchemy ignore the user/password pair and everything after it and connect using the default (and far more secure) mechanism, Windows Authentication - Panagiotis Kanavos