Here is some background on what I am trying to accomplish: My work created an application that stores information in a SQL database for each job we work on. I am trying to automate some of our workflow process using python, but I would like to have access to the information in the database.
From what I understand, to accomplish this I need to connect the database to a SQL server. I am trying to do this using SQLAlchemy and pyodbc. As part of the application I have Microsoft SQL Server 2008 R2 and SQL Server Native Client 10.0 as the driver.
The issue is I am not able to connect to the SQL server using SQLAlchemy or pyodbc using the create_engine() or connect() methods. I have tried a couple different methods below:
1) Using a DSN: I was unable to create a system or user DSN as I would get this error message Error
2) using SQLAlchemy and a hostname connection:
engine = sqlalchemy.create_engine("mssql+pyodbc://user:password@.\DT_SQLEXPR2008/C:\SQLTest\JobDB.mdf?driver=SQL+Server+Native+Client+10.0")
engine.connect()
3) using SQLAlchemy and windows authentication:
engine = sqlalchemy.create_engine('mssql+pyodbc://DT_SQLEXPR2008/C:\SQLTest\JobDB.mdf?driver=SQL+Server+Native+Client+10.0')
engine.connect()
4) Using pyodbc connect() method:
conn = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=.\DT_SQLEXPR2008;DATABASE=C:\SQLTest\JobDB.mdf;UID=user;PWD=password')
In the above I entered my windows username and password in place of "user" and "password". Here is a picture of SQL config. manager showing the existing SQL server and my user I am logged on with.
I have tried setting the server as .\DT_SQLEXPR2008 as well as 'computername'\DT_SQLEXPR2008
Each time I receive this error message:
InterfaceError: (pyodbc.InterfaceError) ('28000', "[28000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'z003vrzk'. (18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'z003vrzk'. (18456)") (Background on this error at: http://sqlalche.me/e/rvf5)
Can anyone tell me how to add a database to a SQL server and read the information it contains?