Skip to content

Getting Connected

Gord Thompson edited this page Apr 7, 2022 · 5 revisions

ODBC DSN Connections

As with other SQLAlchemy dialects that use ODBC, connecting via a DSN is the preferred method. Create the DSN and then refer to it in your connection URL:

from sqlalchemy import create_engine
engine = create_engine("sybase+pyodbc://scott:tiger@your_dsn")

Connecting with an ODBC connection string

You can use a typical ODBC connection string to create a "DSN-less" connection like so:

from sqlalchemy import create_engine
from sqlalchemy.engine import URL

connection_string = (
    "DRIVER=SAP ASE ODBC driver;"
    "SERVER=centos7-vm01;"
    "PORT=5000;"
    "UID=scott;PWD=tiger;"
    "DATABASE=mydatabase;"
    "charset=utf8;"
)
connection_url = URL.create(
    "sybase+pyodbc", 
    query={"odbc_connect": connection_string}
)
engine = create_engine(connection_url)

Hostname Connections

Connection URLs of the form

sybase+pyodbc://scott:tiger@host_name:port/database_name?driver=driver_name

are not supported by this dialect. Use one of the other methods.

Clone this wiki locally