0

I have a database that I am running on my local machine which I can access through Microsoft SQL Server Manager Studio. I connect to this server "JIMS-LAPTOP\SQLEXPRESS" and then I can run queries through the manager. However I need to be able to connect to this database and work with it through python. When I try to connect using sqlite3 like

conn = sqlite3.connect("JIMS-LAPTOP\SQLEXPRESS")

I get an unable to open database file error

I tried accessing the temporary file directly like this

conn = sqlite3.connect("C:\Users\Jim Notaro\AppData\Local\Temp\~vs13A7.sql")
c = conn.cursor()
c.execute("SELECT name FROM sqlite_master WHERE type = \"table\"")
print c.fetchall()

Which allows me to access a database but it is completely empty (No tables are displayed)

I also tried connecting like this

conn = sqlite3.connect("SQL SERVER (SQLEXPRESS)")

Which is what the name is in the sql server configuration manager but that also returns a blank database.

I'm not sure how I am suppose to be connecting to the database using python

1 Answer 1

1

You can't use sqlite3 to connect to SQL server, only to Sqlite databases. You need to use a driver that can talk to MS SQL, like pyodbc.

Sign up to request clarification or add additional context in comments.

2 Comments

My end goal is to use an ORM like sqlalchemy to work with the database. Is it possible to connect to an sql server with that. And if so how would I do that
SqlAlchemy has good docs, you should spend some time with them. An example of a SA connection string I used to connect to SQL server is mssql+pyodbc://server/dbname?driver=SQL+Server+Native+Client+11.0

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.