<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Intermittent pypyodbc connection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151793#M63999</link>
    <description>&lt;P&gt;Thanks for the reply... using PyCharm see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;BR /&gt;import pypyodbc&lt;/P&gt;&lt;P&gt;connStr = pypyodbc.connect("DRIVER={SQL Server};SERVER=server;DATABASE=database;UID=uid;PWD=password")&lt;BR /&gt;query=pd.read_sql("select * from table;",connStr)&lt;BR /&gt;connStr.close()&lt;BR /&gt;print(query)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Mar 2022 16:50:08 GMT</pubDate>
    <dc:creator>JohnConnor01</dc:creator>
    <dc:date>2022-03-08T16:50:08Z</dc:date>
    <item>
      <title>Intermittent pypyodbc connection</title>
      <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151751#M63997</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am experiencing intermittent pypyodbc server connections. I am able to successfully run a simple query on a SQL Server database, and without making changes, the same query won't work 5 minutes later. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;-JC from Boston&lt;/P&gt;&lt;P&gt;(Update: When looking at the debugger, I got an error regarding "Trying to use a closed connection")&lt;/P&gt;&lt;P&gt;(Update: I believe the problem is arising with numerous open/close connections strings in the program and then running certain lines when the connection is inadvertently still closed.)&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 17:31:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151751#M63997</guid>
      <dc:creator>JohnConnor01</dc:creator>
      <dc:date>2022-03-08T17:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent pypyodbc connection</title>
      <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151791#M63998</link>
      <description>&lt;P&gt;Would you share the piece of your code that is creating/using the connection and tell us what environment your creating and running the python in... python window, notebook, Spyder...?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 16:38:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151791#M63998</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-03-08T16:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent pypyodbc connection</title>
      <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151793#M63999</link>
      <description>&lt;P&gt;Thanks for the reply... using PyCharm see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;BR /&gt;import pypyodbc&lt;/P&gt;&lt;P&gt;connStr = pypyodbc.connect("DRIVER={SQL Server};SERVER=server;DATABASE=database;UID=uid;PWD=password")&lt;BR /&gt;query=pd.read_sql("select * from table;",connStr)&lt;BR /&gt;connStr.close()&lt;BR /&gt;print(query)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 16:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151793#M63999</guid>
      <dc:creator>JohnConnor01</dc:creator>
      <dc:date>2022-03-08T16:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent pypyodbc connection</title>
      <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151866#M64001</link>
      <description>&lt;P&gt;If this is stand alone code (I.E. its not embedded in some other code I'm not seeing) than that is odd.&amp;nbsp; I can't replicate the problem, the code works for me (with a slight modification not to return all the records in my test table by using a Where clause on your Select statement)...&lt;/P&gt;&lt;P&gt;Could you have created the connection in one part of your code, closed it, and then tried to call it again later by accident?&lt;/P&gt;&lt;P&gt;For example the code in the first image works because the "conn.close()" is commented out.&amp;nbsp; The second image shows the results of the same code with "conn.close" included and the function call fails:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_1-1646767702207.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35883i6C4EC8271BDB3472/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_1-1646767702207.png" alt="KimGarbade_1-1646767702207.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_0-1646767613084.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35882i90FAAF26DC903575/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_0-1646767613084.png" alt="KimGarbade_0-1646767613084.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only other thing I can think of is that some process running in the database is taking a long time (in computer terms longer than 5 seconds) and your connection is timing out. You could try adding a "timeout=some number of seconds" parameter to your connection string, but that doesn't sound right even to me.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 19:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151866#M64001</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-03-08T19:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Intermittent pypyodbc connection</title>
      <link>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151886#M64002</link>
      <description>&lt;P&gt;Thanks for looking into this Kim, I really appreciate your time! The code is embedded in a very long program, where there are multiple pypyodbc.connect and close() statements - which might be part of the problem - ie maybe its closing when I dont need it to. I might give the connection string a shot just to try it and see what happens. Thanks again for your time.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 20:02:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/intermittent-pypyodbc-connection/m-p/1151886#M64002</guid>
      <dc:creator>JohnConnor01</dc:creator>
      <dc:date>2022-03-08T20:02:01Z</dc:date>
    </item>
  </channel>
</rss>

