0

I'm trying to connect to a SQL Server (SQL Developer 2017) with SQLAlchemy without using a username, password.

from config import msql_serverName, msql_dbName
from sqlalchemy import create_engine

#1st attempt connection_string = f'{msql_serverName}/{msql_dbName}?trusted_connection=yes'

#2nd attempt connection_string = f'{msql_serverName}/{msql_dbName}?Trusted_Connection=yes?driver=ODBC+Driver+17+for+SQL+Server'

connection_string = f'{msql_serverName}/{msql_dbName}?Trusted_Connection=yes?driver=ODBC+Driver+17+for+SQL+Server&authentication=ActiveDirectoryIntegrated'

engine = create_engine(f'mssql+pyodbc://{connection_string}')

connection = engine.connect()

Part1_df.to_sql(name='RepresentationTable1', con=engine, if_exists='append',index=False)

connection.close()
rfkortekaas
  • 6,049
  • 2
  • 27
  • 34
EmekaO
  • 1
  • 1
  • Still getting an error with that: ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]String or binary data would be truncated in table 'representation_v1.dbo.RepresentationTable1', column 'Country'. Truncated value: '\xa0'. (2628) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The statement has been terminated. (3621)") [SQL: INSERT INTO [RepresentationTable1] ([Country], [countryCode], [Population], [LHR], [UHR], [CPRLH], [CPRUH], [Groups]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]....... – EmekaO May 28 '21 at 08:10
  • Yes, but that's a different question than the question above. Please accept the duplicate and search for an answer for the new problem or ask a new question for this problem! – rfkortekaas May 28 '21 at 08:11

0 Answers0