I am running pgdb.connect to make a connection to my postgresql server and cursor to execute queries. For the first time (sometimes twice) it works properly but after that it gives me
OperationalError: Can't start transaction
on "cursor.execute(query)"
Can someone please help me on how to solve this error?
I am using docker compose with one containing postgresql and another a flask server.
Related
I have a Flask App running on an Ubuntu WebApp on Azure. Every morning my queries to the app fail with the below error:
sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x68 (104) (SQLExecDirectW)')
I am using SQLAlchemy ORM to query my Azure SQL Server Instance. I believe that my connections are becoming stale for the following reasons.
It happens every morning after no one uses the app
After X many failed returns, it starts working, until the next morning.
However to make things more weird, when I check sys.dm_exec_sessions on the sql server, it does not show any active connections (outside of the one I'm executing to check).
In addition, when I run the dockerized app on my local and connect to the DB I get no such error.
If anyone has had a similar issue I'd love some insights, or at least a recommendation on where to drill down.
https://azure.github.io/AppService/2018/03/01/Deep-Dive-into-TCP-Connections-in-App-Service-Diagnostics.html
This link helped me, but the solution is only for Windows Apps, not Linux.
With help from #snakecharmerb:
The application was in-fact holding on to a pool of dead connections, setting pool_recycle to a greater time solved the issue.
engine = create_engine(
key, echo=False, future=True,
echo_pool=True,
# connection pool will log informational output such as when connections are invalidated.
pool_recycle=3600
# causes the pool to recycle connections after the given number of seconds has passed.
)
I was trying to close an open DB2 connection for one of my automation script in robot-framework so that I can open a Oracle DB connection and perform certain task. I tried using inbuilt function provided in database library of Robot Framework for closing the connection but it is not closing the connection and giving an error:
AttributeError: "NoneType" object has no attribute "close"
Close method which is written in database library of Robot-Framework is as below:
def disconnect_from_database(self):
self._dbconnection.close()
Steps performed in my scripts are:
Application related validation
Validation in IBM DB2 after connecting
Disconnect IBM DB2
Open Oracle DB and perform certain validation
If I am removing step 3 to disconnect IBM DB2 and directly open oracle connection I am getting error during runtime as
RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class oracle.jdbc.driver.Oracle Driver not found
Please note that oracle db jars are present and script is working fine when I need either DB2 or Oracle DB connection but giving above mentioned error when I need to connect to both the DBs in single script.
Can anyone help me how I can connect to both DBs without these errors?
I'm trying to automatically create a test database before running my tests without shelling out, but I'm struggling to connect to the postgres server without connecting to a database.
If I give create_engine() a URL with .database None it tries to connect to a default database name.
Is what I'm trying to do possible?
I was going a long the lines of this answer: https://stackoverflow.com/a/28784334/311220
One way to achieve this is to connect to the default postgres database which should always be present. Then once connected you can create the desired databases.
I am hosting a web app at pythonanywhere.com and experiencing a strange problem. Every half-hour or so I am getting the OperationalError: (2006, 'MySQL server has gone away'). However, if I resave my wsgi.py file, the error disappears. And then appears again some half-an-hour later...
During the loading of the main page, my app checks a BOOL field in a 1x1 table (basically whether sign-ups should be open or closed). The only other MySQL actions are inserts into another small table, but none of these appear to be associated with the problem.
Any ideas for how I can fix this? I can provide more information as is necessary. Thanks in advance for your help.
EDIT
Problem turned out to be a matter of knowing when certain portions of code run. I assumed that every time a page loaded a new connection was opened. This was not the case; however, I have fixed it now.
It normally because your mysql network connect be disconnected, may by your network gateway/router, so you have two options. One is always build a mysql connect before every query (not using connect pool etc). Second is try and catch this error, then get connect and query db again.
When doing an INSERT with a lot of data, ie:
INSERT INTO table (mediumtext_field) VALUES ('...lots of text here: about 2MB worth...')
MySQL returns
"OperationalError: (2006, 'MySQL server has gone away')"
This is happening within a minute of starting the script, so it is not a timeout issue. Also, mediumtext_field should be able to hold ~16MB of data, so that shouldn't be a problem.
Any ideas what is causing the error or how to work around it?
Some relevant libraries being used: mod_python 3.3.1, MySQL 5.0.51 (on Windows XP SP3, via xampp, details below)
ApacheFriends XAMPP (basic package) version 1.6.5
Apache 2.2.6
MySQL 5.0.51
phpMyAdmin 2.11.3
check the max_packet setting in your my.cnf file. this determines the largest amount of data you can send to your mysql server in a single statement. exceeding this values results in that error.