LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2017, 04:27 PM   #1
xedge
LQ Newbie
 
Registered: Aug 2017
Location: Mexico
Distribution: Ubuntu 14.04, OS X High Sierra,
Posts: 16

Rep: Reputation: Disabled
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.
 
Old 10-09-2017, 08:25 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,321

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Whenever you get this error, reopen your database-connection.
 
1 members found this post helpful.
Old 10-12-2017, 11:44 AM   #3
xedge
LQ Newbie
 
Registered: Aug 2017
Location: Mexico
Distribution: Ubuntu 14.04, OS X High Sierra,
Posts: 16

Original Poster
Rep: Reputation: Disabled
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!
 
  


Reply

Tags
mac, python, sql server


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
2016 MBP not waking up from sleep designator Linux - Laptop and Netbook 3 08-28-2017 12:50 PM
Black Screen when waking from a sleep Ubuntu 13.04 actyler1012 Linux - Newbie 1 05-19-2013 05:32 PM
WPA authentication fails after waking from sleep vs. dLink (Ubuntu 10.04) dewdrop_world Linux - Wireless Networking 3 05-12-2011 05:54 PM
Waking from S3 sleep doesn't turn the screen on (Asus A6U) MasterOfTheWind Linux - Laptop and Netbook 2 05-03-2011 03:06 AM
Waking my computer up after it goes to sleep Fosforo Ubuntu 4 01-20-2007 03:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration