python - Pyodbc Error when creating SQLAlchemy Engine -
i trying write pandas dataframe called df
table in sql express in code below, error dbapierror: (pyodbc.error) ('im002', '[im002] [microsoft][odbc driver manager] data source name not found , no default driver specified (0) (sqldriverconnect)')
in line engine = sqlalchemy.create_engine('mssql://lenovo-pc\sqlexpress\\sqlexpress/databasewithinfo?trusted_connection=yes')
. saw answer in this post , tried follow that. know server_name = lenovo-pc\sqlexpress
, database_name = databasewithinfo
, struggling understand i'm going wrong.
import sqlalchemy sqlalchemy import create_engine engine = sqlalchemy.create_engine('mssql://lenovo-pc\sqlexpress\\sqlexpress/databasewithinfo?trusted_connection=yes') df.to_sql('jpy_data', engine, chunksize=1000)
thank you
this isn't directly answer, toolkit test connection variants until works.
you want throw many connect strings variants can @ until works. i've put in 2 already.
i did notice post refer has sqlexpress once in connect string, unlike you.
import sqlalchemy sqlalchemy import create_engine def test_it(t_connect_string): #these connection setting, constant di = dict(server="lenovo-pc",database="databasewithinfo") connect_string = t_connect_string % di try: engine = sqlalchemy.create_engine(connect_string) print "%s success!" % (connect_string) return true except exception, e: print "%s exception=>%s" % (connect_string, e) return false #put many possible templates need until connects, you're li_test = [ """mssql://%(server)s\sqlexpress\\sqlexpress/%(database)s?trusted_connection=yes""", #the post refer seems have format instead... """mssql://%(server)s\\sqlexpress/%(database)s?trusted_connection=yes """, ] #test them until works. test in li_test: result = test_it(test) if result: break
it blows me, because don't odbc installed, you'll more relevant errors hopefully.
mssql://lenovo-pc\sqlexpress\sqlexpress/databasewithinfo?trusted_connection=yes exception=>no module named pyodbc mssql://lenovo-pc\sqlexpress/databasewithinfo?trusted_connection=yes exception=>no module named pyodbc
Comments
Post a Comment