LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Persistent db connection after waking up a computer from sleep? (https://www.linuxquestions.org/questions/programming-9/persistent-db-connection-after-waking-up-a-computer-from-sleep-4175615332/)

xedge 10-09-2017 03:27 PM

Persistent db connection after waking up a computer from sleep?
 
I'm developing a python app for MAC that interacts with an SQL Server Database after some hardware tests. I have a text box that makes a query into a table on the database and returns if that information has been passed to the test previously or not.

One of the tests that the computer has to pass it's a 10 sleep cycle test.

The main problem here is that whenever I want to make a query again with that text box it throws me the following error.

Code:

pyodbc.Error ('[08S01]', '[08S01] [Microsoft][ODBC Driver 13 for SQL Server]Communication link failure (0) (SQLEndTran)')
Here's how I declared the connection string:

Code:

db = pyodbc.connect(driver='{ODBC Driver 13 for SQL Server}', host='servername', database='db', user='user', password='pass')
And here's a snippet of the code:

Code:

cur = db.cursor()
try:
    query = "SELECT [ID] FROM [dbo].[Archive] WHERE [Number] = '%s'"
    cur.execute(query % (numberVariable))
    db_info = cur.fetchone()
    cur.close()
    db.commit()
    return db_info[0]
except Exception as e:
    cur.close()
    db.commit()
    print "Error 103: Error getting number in database"

Any help will be appreciated.

NevemTeve 10-09-2017 07:25 PM

Whenever you get this error, reopen your database-connection.

xedge 10-12-2017 10:44 AM

Found solution
 
Setting pyodbc.pooling = False, did the trick. Supposedly this option keeps persistent connection and I think that when the computer goes to sleep it interrupts the connection and throws the error message. Thank you for your answer!


All times are GMT -5. The time now is 03:25 PM.