0

I can connect to the sql-server database and read data from python using,

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=server_name;DATABASE=testdb;UID=Another_Domain\\username;PWD=pass; Trusted connection=YES')

But when I try to write data from python to sql-server using,

engine = create_engine('mssql+pyodbc://user:password@host:port/myDB')
conn = engine.connect()

I get an error,

InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') (Background on this error at: http://sqlalche.me/e/rvf5)

How can I connect?

2
  • Unrelated, specifically, to the question you're asking, however, if you're using a Trusted connection in the first statement, why are you passing a Username and password? It's one or the other. Commented Mar 11, 2020 at 13:04
  • The second block seems to come from sqlalchemy, and its connection syntax is very different from pyodbc. You have to assign the driver string explicitly. You may refer to the following MWE (minimum working example) and see if it works. stackoverflow.com/a/60636359/3218693 Commented Mar 11, 2020 at 13:09

1 Answer 1

0

Maybe the way you can connect is:

create_engine('mssql+pymssql://{domain}\{username}:{password}@{hostip}:{port}/{db}')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.