I am trying to connect Python 2.7 to SQL Server to access all the tables it is currently hosting.
I am using for my official purposes so want only legal solutions to my problem.
Tried using a few of the solutions suggested her but none of them worked and most of them were not at all descriptive as I am new to Python.
Also is it possible to import a large table from SQL directly as a temp table(in python) and then work on it instead of accessing the DB everytime.
Details:
OS- Windows 10
DB- SQL Server 2012 (SQL server management studio)
Python- Spyder(Anaconda) for Python 2.7
thanks in advance for your help.
regards
Hitesh
Related
I use SQLite3 in python because my school computers don't allow us to install anything to python so I used the pre installed SQLite3 module.
I'm working on a program whose back end relies on an SQLite3 database, however the databases are created and stored on their computer.
Is it possible for me to "Host" an SQLite3 database on let's say a server and allow my script to access them remotely (my script could edit the database from my school computer)?
By the way, I'm using python 3.X
EDIT
i made a database api that runs in python 3, its called TaliffDb
to install type pip3 install TaliffDB in your terminal. im working on a documentation, but please do comment if you have any questions
Write an API on the remote server, yes. This could be hosted by a web framework of your choice.
You won't get a direct network connection to a file
im working on python application that requiring database connections..I had developed my application with sqlite3 but it start showing the error(the database is locked).. so I decided to use MySQL database instead.. and it is pretty good with no error..
the only one problem is that I need to ask every user using my application to install MySQL server on his pc (appserv for example) ..
so can I make mysql to be like sqlite3 apart of python lib. so I can produce a python script can be converted into exe file by the tool pyInstaller.exe and no need to install mysql server by users???
update:
after reviewing the code I found opened connection not closed correctly and work fine with sqllite3 ..thank you every body
It depends (more "depends" in the answer).
If you need to share the data between the users of your application - you need a mysql database server somewhere setup, your application would need to have an access to it. And, the performance can really depend on the network - depends on how heavily would the application use the database. The application itself would only need to know how to "speak" with the database server - python mysql driver, like MySQLdb or pymysql.
If you don't need to share the data between users - then sqlite may be an option. Or may be not - depends on what do you want to store there, what for and what do you need to do with the data.
So, more questions than answers, probably it was more suitable for a comment. At least, think about what I've said.
Also see:
https://stackoverflow.com/questions/1009438/which-database-should-i-use-for-my-desktop-application
Python Desktop Application Database
Python Framework for Desktop Database Application
Hope that helps.
If your application is a stand-alone system such that each user maintains their own private database then you have no alternative to install MySQL on each system that is running the application. You cannot bundle MySQL into your application such that it does not require a separate installation.
There is an embedded version of MySQL that you can build into your application (thanks, Carsten, in the comments, for pointing this out). More information is here: http://mysql-python.blogspot.com/. It may take some effort to get this working (on Windows you apparently need to build it from source code) and will take some more work to get it packaged up when you generate your executable, but this might be a MySQL solution for you.
I've just finished updating a web application using SQLite which had begun reporting Database is locked errors as the usage scaled up. By rewriting the database code with care I was able to produce a system that can handle moderate to heavy usage (in the context of a 15 person company) reliably still using SQLite -- you have to be careful to keep your connections around for the minimum time necessary and always call .close() on them. If your application is really single-user you should have no problem supporting it using SQLite -- and that's doubly true if it's single-threaded.
I have a website on an Australian webhost. I have designed my website to allow people to login & their login details are stored in an SQLite3 database. I interact with the SQLite3 database using pythons SQLite3 module(found only in python2.5 & up)
My Problem: the webhost runs Python 2.4 so I cannot communicate with(query or modify) my SQLite3 database. The webhost will not allow me to install my own version of python or upload modules unless I upgrade to VPS.
What do you think are my options to still be able to work/interface with my SQL database? Do you know of way to interact with a SQL database using python modules from Python 2.4 or earlier?
Do you know of a python 2.4 module that will let me interact with an SQL database(can be MySQL, SQLite, etc.)?
There is a Python MySQL Module, called MySQLDB, which supports Python 2.3-2.7: http://sourceforge.net/projects/mysql-python/
The User Guide can be found here: http://mysql-python.sourceforge.net/MySQLdb.html
Check out pysqlite. It is the same module as in the newer python versions and I have used it no prob in 2.4 before.
Can any of you recommend a free database engine with a Python client & gui tools (to run queries etc) that is working well with Ubuntu?
I would simply go to MySQL, but from what I know, it's Python client is not being maintained (I am searching for a database engine that has a good, working Python client)
Personally I'd go with PostgreSQL, but oursql.
What is the best way to access sql server from python is it DB-API ?
Also could someone provide a such code using the DB-API how to connect to sql server from python and excute query ?
See pyodbc - Python Database API Specification v2.0 implementation. Works great.
Additionally you can use it with other databases. If using with SQL Server 2008, make sure you use Native Driver if you need to support new DATE data types.
See pymssql It is a DB-API module for MS Sql Server and would be the most pythonic way. The documentation includes examples.
If on a Windows OS you could also use OLEDB through COM which will not require any thing else to be installed on the client.
Also if you use Iron Python you can use the .Net APIs
Also could someone provide a such code using the DB-API
how to connect to sql server from python and excute query ?
This hello world snippet pretty much shows you the common way how to connect with SQL server in Python with an DBI 2.0 database interface module.
Disclaimer: I'm the developer of pypyodbc
ODBC + freetds + a python wrapper library for ODBC.