Tagged Questions
14
votes
2answers
3k views
Avoiding “MySQL server has gone away” on infrequently used Python / Flask server with SQLAlchemy
How can Flask / SQLAlchemy be configured to create a new database connection if one is not present?
I have an infrequently visited Python / Flask server which uses SQLAlchemy. It gets visited every ...
11
votes
4answers
3k views
What if I don't close the database connection in Python SQLite
I am doing something like this...
conn = sqlite3.connect(db_filename)
with conn:
cur = conn.cursor()
cur.execute( ... )
with automatically commits the changes. But the docs say nothing ...
9
votes
10answers
8k views
Multiple database support in django
From some forum I came to know that Multiple database support is added in Django at lower level, but the higher level apis are not added yet.
Can anyone please tell me how one can achieve multiple ...
8
votes
4answers
14k views
How can I access Oracle from Python?
How can I access Oracle from Python? I have downloaded a cx_Oracle msi installer, but Python can't import the library.
I get the following error:
import cx_Oracle
Traceback (most recent call last):
...
8
votes
1answer
310 views
How to properly handle Redis connections with Python / Python RQ?
What is the best pattern to handle Redis connections (both for interacting with Redis directly and indirectly through Python-RQ)?
Generally, database connections need to be closed / returned to a ...
7
votes
4answers
2k views
In Python, how to make sure database connection will always close before leaving a code block?
I want to prevent database connection being open as much as possible, because this code will run on an intensive used server and people here already told me database connections should always be ...
7
votes
2answers
1k views
How to use a different database per “application instance” in Django?
The scenario
We have two applications.
TheApp
TheApp is an incredible app which customers love. Each customer gets his own
instance of the application, which means each customer will use a ...
6
votes
5answers
8k views
What's causing 'unable to connect to data source' for pyodbc?
I'm trying to connect to an MSSQL database from python on Linux (SLES).
I have installed pyodbc and Free TDS. From the command line:
tsql -H server -p 1433 -U username -P password
Connects to the ...
6
votes
1answer
2k views
Create DB connection and maintain on multiple processes (multiprocessing)
Similar to another post I made, this answers that post and creates a new question.
Recap: I need to update every record in a spatial database in which I have a data set of points that overlay data ...
5
votes
2answers
5k views
How to tell if Python SQLite database connection or cursor is closed?
Let's say that you have the following code:
import sqlite3
conn = sqlite3.connect('mydb')
cur = conn.cursor()
# some database actions
cur.close()
conn.close()
# more code below
If I try to use the ...
4
votes
1answer
339 views
how to reconnect with MS SQL after hibernation (S4) (or dropped connection)?
I'm running some hibernation tests using python + microsoft's pwrtest utility
Also I'm using sqlalchemy (orm) to work with database (ms sql server 2008 r2).
I'm connected to the remote sql server ...
3
votes
3answers
5k views
Python Database connection Close
Using the code below leaves me with an open connection, how do I close?
import pyodbc
conn = pyodbc.connect('DRIVER=MySQL ODBC 5.1 driver;SERVER=localhost;DATABASE=spt;UID=who;PWD=testest')
csr ...
3
votes
2answers
2k views
MySQLdb with multiple transaction per connection
Is it okay to use a single MySQLdb connection for multiple transactions without closing the connection between them? In other words, something like this:
conn = MySQLdb.connect(host="1.2.3.4", ...
3
votes
2answers
1k views
set up a MySQLdb connection object for multiple databases
This question is likely noobish.
Instead of hardcoding the MySQLdb connection object: e.g,
db = MySQLdb.connect('localhost','name','pwrd','db_name')
How do I set it up so I can specify the db_name ...
3
votes
3answers
6k views
Connecting to Sql Server with Python 3 in Windows
Can someone please point me in the right direction of how I can connect to MS SQL Server with Python? What I want to do is read a text file, extract some values and then insert the values from the ...
3
votes
3answers
28 views
Necessity of explicit cursor.close()
From time to time, I'm executing raw queries using connection.cursor() instead of using ORM (since it is definitely not a silver bullet).
I've noticed that in several places I don't call explicit ...
3
votes
1answer
782 views
MongoDB Connection Management in Python
Is it better to do
from pymongo import Connection
conn = Connection()
db = conn.db_name
def contrivedExample(firstName)
global db
return db.people.find_one({'first-name': firstName})
or
...
3
votes
1answer
185 views
What is the process for using MySQL from Python in Windows?
I come from a PHP background where MySQL easily works from PHP, and don't the process for getting MySQL to work from Python. From all the research i did and reading of similar yet non-exact ...
3
votes
3answers
541 views
Inter-database communications in PostgreSQL
I am using PostgreSQL 8.4. I really like the new unnest() and array_agg() features; it is about time they realize the dynamic processing potential of their Arrays!
Anyway, I am working on web server ...
2
votes
2answers
444 views
web2py webserver - Best way to keep connection to external SQL server?
I have a simple web2py server that we use to visualize data from our PostgreSQL Server. The following functions are all part of the global models in web2py.
The current solution to fetch data is very ...
2
votes
1answer
47 views
What are the drawbacks and advantages to implementing namespacing with databases in Redis?
Trying to organize our Redis keyspaces in a simple and (somewhat) extensible way, we've found an interesting mechanism: databases. The idea would be to a name (say person, for example) to a database ...
2
votes
1answer
132 views
Python: decryption failed or bad record mac when calling from Thread
I'm getting a "decryption failed or bad record mac" error in this code-fragment:
conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("SELECT id, ip FROM schema.table;")
rows = ...
2
votes
0answers
621 views
Python MySQLdb connection - when to open/close new connections?
I'm using a few apps running Tornado Web server which all connect to a MySql DB using mysqldb. When I spin up the server, it instantiates a DB class (below) which opens a connection to the DB. All ...
2
votes
4answers
926 views
How to use IBM_DB with older versions of DB2?
I want to connect Python to DB2 version 9.1 using IBM DB2 ODBC Driver.
Following is my code to connect Python to DB2. This program is working in the later versions of IBM DB2.
import ibm_db
conn = ...
1
vote
3answers
4k views
1049, “Unknown database 'database' ” django mysql can't connect
Exception Type: OperationalError at /
Exception Value: (1049, "Unknown database 'database'")
At the moment i tried this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', ...
1
vote
1answer
75 views
what is Python 2.x database interface?
I am re-writng a perl program using python. In the perl program, it’s using perl database interface (DBI) to perform Oracle database operations. For example, DBI->connect to connect a database, and ...
1
vote
3answers
3k views
Python and MySQL connection problems (mysqldb api)
I have config.ini:
[mysql]
host=localhost
port=3306
user=root
passwd=abcdefgh
db=testdb
unix_socket=/opt/lampp/var/mysql/mysql.sock
I have this class:
#!/usr/bin/python
import MySQLdb,ConfigParser
...
1
vote
1answer
1k views
Open/Close database connection in django
I am using Django and Postgresql as my DBMS.
I wish to set a setting that enables to enable/disable database connection. When the connection is set to closed (in settings.py) the site will display a ...
1
vote
2answers
927 views
Update database with multiple SQL Statments
I am using mysql connector.Python 1.0.9 downloaded from MySQL site.
I have a sample table here
DROP TABLE IF EXISTS my_table;
CREATE TABLE my_table
(id INT NOT NULL AUTO_INCREMENT UNIQUE,
Shot ...
1
vote
1answer
371 views
How to access a database in Django but without ORM support
I have a second database in my Django application, which is filled with static data about the equivalent of zipcodes in my country (Brazil) and the related streets, neighborhoods, cities and states.
...
1
vote
1answer
35 views
python close mysql database connection
I have a python script which uses a MySQL database connection, I want the database connection to be closed when the instance of the class does no longer exist therefore in my class I implemented a ...
1
vote
1answer
474 views
Python Connect to Oracle DB
I currently use PYODBC to connect to MS SQL Server and MYSQL, but now need to access an Oracle database as well.
I have Oracle SQL Developer installed on my work comp (but there doesn't seem to be ...
1
vote
1answer
669 views
OperationalError: unable to open database file in PyCharm with Flask IDE plug-in
I have been struggling with this for the better part of the day. I am absolutely incapable of connecting to my database in PyCharm. I even follow the video tutorial exactly while downloading the ...
1
vote
1answer
138 views
How can I connect a SQLite local database to a HTML frontend?
I've recently ported a simple database from Ms Access to SQLite, because I wanted an open source option. Now I'm facing the problem of developing a visual form for data entry in that database.
This ...
1
vote
2answers
97 views
Two connections/cursors in mysqldb - commands out of sync error
I'm using mysqldb in part of a script to copy information from one database to another. A snippet of the code I have is as follows:
connection1 = mysqldb.connect('localhost', 'root', 'password', ...
1
vote
0answers
89 views
Select a single active database connection when starting Plone
I have a Plone 4 site which uses an additional Postgres database via a Z Psycopg 2 Database Connection object. Since the ZODB is sometimes replicated for testing and development purposes, there are a ...
1
vote
0answers
182 views
Connect to informix with python's ibm_db
I'm pretty new to python. I'm trying to connect to an informix server using python and ibm_db.connect(). However I can't seem to succeed and the error messages don't help.
Using java and jdbc I can ...
1
vote
0answers
124 views
pymssql error 20009 while connecting to db
This is driving me crazy and I can't figure out. I installed pymssql on my Mac and was using it without any problem. And then one day it stopped working. I have no idea why. I can run the same code on ...
1
vote
0answers
253 views
Unable to connect using pymssql with windows authentication
While trying to connect to MSSQL Server 2012 using pymssql, I get the following error.
My server name in Windows Authentication is SARATH,User Name is Sarath\SarathShanker and I did not set a ...
1
vote
0answers
84 views
ImportError: No localization support for language 'eng' in python
i am getting ImportError: No localization support for language 'eng' when using MySQL Connector Python.
My Traceback is as below.
Traceback (most recent call last):
File \"DB_Module.py\", line 151, ...
1
vote
1answer
1k views
Closing a cx_Oracle Connection While Allowing for a Down Database
The following cx_Oracle code works fine when the database is up:
#!C:\Python27
import cx_Oracle
try:
conn = cx_Oracle.connect("scott/tiger@oracle")
try:
curs = conn.cursor()
...
0
votes
3answers
787 views
Automate Opening and Closing the Database Connection
I am writing a class for database queries with SQLite3 in my application. Most of the methods of the class are very similar to this:
def getPrice(self, symbol, date):
date = ...
0
votes
3answers
390 views
db connection in python
I am writing a code in python in which I established a connection with database.I have queries in a loop.While queries being executed in the loop ,If i unplug the network cable it should stop with an ...
0
votes
3answers
387 views
Uploading a mysql database to a webserver supporting python
I have a written a very small web-based survey using cgi with python(This is my first web app. ).The questions are extracted from a MySQL database table and the results are supposed to be saved in the ...
0
votes
1answer
1k views
How to connect to a database through a Paramiko Tunnel (or similar package)
I am having serious issues setting up a proper tunnel in paramiko to enable a database connection. I have reviewed the example 'forward.py', but am not understanding how to then link the database ...
0
votes
2answers
26 views
Python: Dealing with MySQL connect hanging
I am starting a large number of python jobs simultaneously on a cloud computing provider (about 320 jobs). Each of the python jobs makes a few connections to a MySQL server when they start. The ...
0
votes
1answer
34 views
Connect to local Oracle database from online website
I have a "local" Oracle database in my work network. I also have a website at a hosting service.
Can I connect to the 'local' Oracle database from the hosting service? Or does the Oracle database ...
0
votes
1answer
199 views
Python mysql (using pymysql) auto reconnect
I'm not sure if this is possible, but I'm looking for a way to reconnect to mysql database when the connection is lost. All the connections are held in a gevent queue but that shouldn't matter I ...
0
votes
1answer
21 views
Getting connection object in generic model class
I have a Model class which is part of my self-crafted ORM. It has all kind of methods like save(), create() and so on. Now, the thing is that all these methods require a connection object to act ...
0
votes
1answer
50 views
speed of databases versus data structures - which one to use for real time view of multiprocessing? [closed]
Question: Is a database fast enough to manipulate data in a loop?
I have been attempting to increase the speed of an application which will perform very large processes on data in real time. My hope ...