zillow / ctds

Python DB-API 2.0 library for MS SQL Server
MIT License
83 stars 12 forks source link

Adaptive Server connection timed out #94

Open benedikt-mue opened 2 years ago

benedikt-mue commented 2 years ago

I am encountering a rather odd behavior when trying to execute an UPDATE stmt:

connection = ctds.connect(DATABASE_HOST, user=DATABASE_USER, password=DATABASE_PASSWD,
 database=DATABASE_NAME)

with connection as conn:
        conn.cursor().execute("""
            --SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
                UPDATE [dbo].[test] 
                SET
                    col1 = s.col1,
                    col2 = s.col2,
                    col3 = s.col3,
                    col4 = s.col4
            FROM dbo.source s
                WHERE [dbo].[test].row_key = s.row_key
            ;
        """)

Results in: DatabaseError: Adaptive Server connection timed out

However, executing the exact same stmt in DataStudio, it does work as intended.

Versions: ctds version: 1.14.0 FreeTDS version: freetds v1.2.10

burkol commented 1 year ago

Hi

I faced this issue on Ubuntu 20.04.3 LTS. After the following env settings the problem is solved: export TDSVER=8.0 export LANG=en_US.UTF-8

josephraj2k16 commented 1 year ago

Hi

I faced this issue on Ubuntu 20.04.3 LTS. After the following env settings the problem is solved: export TDSVER=8.0 export LANG=en_US.UTF-8

Where to include this env settings? I'am using Linux in my end

tf-njk commented 1 year ago

Hi

I am facing this same issue with ctds.connect(), where can I put @burkol's settings to fix this? or what is the best way to fix this?

@benedikt-mue @almonteb @kadrach @robatron

burkol commented 1 year ago

Hi All,

I've a script with 3 lines:

. ~/envs/dataloader_batch_env/bin/activate
. ~/batches/env.sh
python3 ~/batches/dataloader.py

The env.sh contains the mentioned settings:

export TDSVER=7.3
export LANG=en_US.UTF-8

Note: Changed the 8.0 to 7.3 because of date conversion issue. This line wasn't work with 8.0 ctds.SqlVarChar('2011-01-01'.encode('utf-16le'))

In the dataloader.py the connection looks like:

from ctds import connect as SqlConnect
connection_setting = {
    'server': "<server_name>.database.windows.net", 
    'database': "<database_name>", 
    'user': "<user_name>@<server_name>", 
    'password': "<password>"
}

with SqlConnect(**connection_setting) as connection:

I hope I could help

HuangRicky commented 1 year ago

You need to have the freetds installed . Also, often a time if you are behind a firewall, you may forget to set proxy in your python settings. Third, your connection string may be missing something, often the port number. You need to Google how to construct the correct connection string for your server. Is it sql server? Sybase?

On Wed, Oct 27, 2021, 9:41 AM benedikt-mue @.***> wrote:

I am encountering a rather odd behavior when trying to execute an UPDATE stmt:

connection = ctds.connect(DATABASE_HOST, user=DATABASE_USER, password=DATABASE_PASSWD, database=DATABASE_NAME)

with connection as conn: conn.cursor().execute(""" --SET TRANSACTION ISOLATION LEVEL READ COMMITTED; UPDATE [dbo].[test] SET col1 = s.col1, col2 = s.col2, col3 = s.col3, col4 = s.col4 FROM dbo.source s WHERE [dbo].[test].row_key = s.row_key ; """)

Results in: DatabaseError: Adaptive Server connection timed out

However, executing the exact same stmt in DataStudio, it does work as intended.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zillow/ctds/issues/94, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWEAWOFUXFMAMYSL5UWDBTUJAFP3ANCNFSM5G2MNXFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.