Untitled

 avatar
unknown
plain_text
a month ago
1.1 kB
4
Indexable
import cx_Oracle

import configparser

import sys

import os

 

def read_config():

    config = configparser.ConfigParser()

    config.read('config.ini')

    return {

        'username': config['database']['username'],

        'password': config['database']['password'],

        'dsn': config['database']['dsn']

    }

 

def test_connection(db_config):

    try:

        # Set Oracle Client location - update this path to match your installation

        lib_dir = r"U:\New folder\instantclient_23_6"

        cx_Oracle.init_oracle_client(lib_dir=lib_dir)

        

        connection = cx_Oracle.connect(

            db_config['username'],

            db_config['password'],

            db_config['dsn']

        )

        print("Successfully connected to Oracle Database")

        connection.close()

    except Exception as err:

        print(f"Error connecting to database: {err}")

        sys.exit(1)

 

if __name__ == "__main__":

    db_config = read_config()

    test_connection(db_config)
Editor is loading...
Leave a Comment