gvenzl / oci-oracle-xe

Build scripts for Oracle Database XE container/docker images
Apache License 2.0
257 stars 77 forks source link

How to connect to database from host #201

Closed SoumayaMauthoorMOJ closed 1 year ago

SoumayaMauthoorMOJ commented 1 year ago

I have created a docker container using the following script:

docker run -d --name oracle_db \
-p 1521:1521 \
-e ORACLE_RANDOM_PASSWORD="y" \
-e APP_USER="my_user" \
-e APP_USER_PASSWORD="my_password" \
gvenzl/oracle-xe

I can connect to the database after exec'ing into the container:

$ docker exec -ti oracle_db bash
bash-4.4$ sqlplus my_user/my_password@localhost:1521/XEPDB1

SQL*Plus: Release 21.0.0.0.0 - Production on Sun Apr 9 16:27:07 2023
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle.  All rights reserved.

Last Successful login time: Sun Apr 09 2023 16:23:08 +00:00

Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

SQL> 

However I can't connect to the database from the host. I have tried setting the host to localhost, 127.0.0.1 and I get the following error message:

error_num = 6005, context_error_message = 'DPY-6003: SID "XEPDB1" is not registered with the listener at host "127.0.0.1" port 1521. (Similar to ORA-12505)'
cause = OperationalError(<oracledb.errors._Error object at 0x11c0a0130>), args = {}
message = 'DPY-6005: cannot connect to database.\nDPY-6003: SID "XEPDB1" is not registered with the listener at host "127.0.0.1" port 1521. (Similar to ORA-12505)'
exc_type = <class 'oracledb.exceptions.OperationalError'>

Any thoughts?

SoumayaMauthoorMOJ commented 1 year ago

All fixed - I should have used the service name instead!

amardeep2006 commented 11 months ago

I did face the similar error while connecting using java drivers. It worked after using following format of conn string

Driver : oracle.jdbc.OracleDriver

Working Connection String: jdbc:oracle:thin:@localhost:1521/XEPDB1

I was using this format : jdbc:oracle:thin:@localhost:1521:XEPDB1