0

I'm trying to query via pd.read_sql(sql, db_connection_dw)

The connection works properly and is the following:

driver= '{Devart ODBC Driver for ASE}'
server='---' 
db_environment='----'
username='----'
password='----'
port='----'
connectionString = 
('DRIVER='+driver+';SERVER='+server+';PORT='+port+';UID='+username+';PWD='+ 
password + ';DATABASE='+db_environment)
try:
    db_connection_dw = pyodbc.connect(connectionString)
except:
    print('could not connect')
    exit(0)

The query is the following, which is a simple one that returns the first 10 registers:

sql = """SELECT TOP 10 VariableID, 
            PatientID, 
            CONVERT(VARCHAR(10), ValueTime, 23) as ValueTime 
     FROM PV_VariableValues 
     WHERE VariableID = 15002262 and NumValue = 12 and YEAR(ValueTime) = 2019 and 
     MONTH(ValueTime) = 7
     """

After using pd.read_sql(sql, db_connection_dw) it returns the following Dataframe:

    VariableID  PatientID   ValueTime
0   15002262    9811        2019-07-02
1   15002262    9811        2019-07-02
2   15002262    9811        2019-07-03
3   15002262    9811        2019-07-03
4   15002262    9811        2019-07-03
5   15002262    9811        2019-07-03
6   15002262    9811        2019-07-04
7   15002262    9811        2019-07-04
8   15002262    9811        2019-07-04
9   15002262    9922        2019-07-25

The problem comes when I make a bigger query, let's say, the TOP 1000. After running the code it returns the following error:

Error: ('HY000', '[HY000] [Devart][ODBC][Adaptive Server Enterprise]Error on data reading from the connection:\r\nSe produjo un error durante el intento de conexión ya que la parte conectada no respondió adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexión establecida ya que el host conectado no ha podido responder.\r\nSocket Error Code: 10060($274C) (0) (SQLFetch)')

An alternative that I tried is to read via chunksize argument doing the following after the declaration of the sql string:

for chunk in pd.read_sql(sql, db_connection_dw, chunksize=10):
    print(chunk)

But after some prints it stops and returns the same error.

Any idea?

Thank's for advance

jordi588
  • 37
  • 7

1 Answers1

0

Since you are connecting to a sybase database, try changing this part:

driver ='{Adaptive Server Enterprise}'

ensure that the drivers are installed. To check a list of ODBC installed drivers from python, run the following code:

import pyodbc

pyodbc.drivers()

You should see the driver name '{Adaptive Server Enterprise}' if it is installed.

Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
One Pablo
  • 63
  • 7
  • You mean this one? https://www.sap.com/cmp/syb/crm-xu15-int-asewindm/index.html?url_id=text-es-sapcom-ase-trial-software, but this is not free! And takes more than 2 GB compressed – jordi588 Oct 01 '19 at 13:52
  • After installing the driver '{Adaptive Server Enterprise}', the problem persist – jordi588 Oct 02 '19 at 12:41
  • Is your version of python and the version of the driver the same? That is, are they both 32/64 bit? I previously found that to be one the issues that cause problems – One Pablo Oct 02 '19 at 20:13
  • It seems that with the driver '{Adaptive Server Enterprise}' and following this steps http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01265.0330/doc/html/git1253740559178.html the problem is solved – jordi588 Oct 04 '19 at 10:53