Getting "ORA-28000: the account is locked" while connecting from Python to Oracle - cx-oracle

I have Python (3.8.3) and Oracle DB (11g Release 2 server) installed in my local system. Both of the software are working fine individually. I can run programs in python as well as I have tables created with data in Oracle DB which I am able to access through Oracle SQL Developer & SQL Plus.
But when I am trying to connect Oracle DB from python I am getting error as account locked. I have installed and executed import cx_Oracle successfully. But I am getting error when I am trying to execute below code.
1. Local initialization method -
connection = cx_Oracle.connect("oe/oracle#localhost:1522/orcl11g2")
2. Connecting through TNSNAMES.ORA -
connection = cx_Oracle.connect("oe", "oracle", "orcl11g2")
Error -
Traceback (most recent call last):
File "", line 1, in
cx_Oracle.DatabaseError: ORA-28000: the account is locked
My TNS Details -
File location - D:\app\Admin\product\11.2.0\dbhome_2\NETWORK\ADMIN
ORCL11G2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL11G2)
)
)
Please help me. Just let me know if you need to know anything more to guide me.

In SQL Developer or SQL*Plus, connect to the DB as a privileged user such as SYSTEM or SYS, e.g:
sqlplus system/yourpassword#localhost:1522/orcl11g2
Then run the SQL statement:
alter user oe account unlock;

Related

SAP ASE Extension Python Module: #stmt_query_timeout?

I am trying to move from a Windows-based pyodbc (Using the SAP Adaptive Server Enterprise 16.0 driver) to Red Hat Linux 7.9-based sybpydb solution.
Current pyodbc solution:
connection = pyodbc.connect(
"Driver={Adaptive Server Enterprise};NetworkAddress=<servername,serverport>;
Database=<database>;UID={<username>};PWD={<password>};#pool_size=10;
stmtquery_timeout=1200;#login_timeout=30;#connection_timeout=30")
df = pandas.read_sql_query("exec <storedproc_name>")
connection.close()
I am trying to replicate this under linux using the sybclient-16.0.3-2 package.
import sybpydb
connection = sybpydb.connect(user=username, password=password, servername=servername,
dsn="HostName=<hostname>;Database=<database>;LoginTimeout=30;Timeout=30")
curr = connection.cursor()
result = cursor.execute("exec <storedproc_name>")
Passing #smtmquery_timeout=1200 causes the connection to fail. But without this, the call to the stored proc will timeout. I can't see anything in the documentation about this.
Thanks in advance
Please refer to the document:
https://help.sap.com/docs/SAP_ASE_SDK/a1576559612d4e39886fc0ad4e093074/b0fd2586bbf910148c6ac638f6594153.html
There is no attribute: smtmquery_timeout
If you are using "sybpydb", you can use the openclient sdk directly instead of the ODBC style configuration for the connection.

Connecting to Azure PostgreSQL server from python psycopg2 client

I have trouble connecting to the Azure postgres database from python. I am following the guide here - https://learn.microsoft.com/cs-cz/azure/postgresql/connect-python
I have basically the same code for setting up the connection.
But the psycopg2 and SQLalchemy throw me the same error:
OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
I am able to connect to the instance by other client tools like dbeaver but from python it does not work.
When I investigate in Postgres logs I can see that the server actually authorized the connection but the next line says
could not receive data from client: An existing connection was forcibly closed by the remote host.
Python is 3.7
psycopg's version is 2.8.5
Azure Postgres region is in West Europe
Does someone has any suggestion on what should I try to make it work?
Thank you!
EDIT:
The issue resolved itself. I tried the same setup a few days later and it started working. Might have been something wrong with the Azure West Europe.
I had this issue too. I think I read somewhere (I forget where) that Azure has an issue with the # you have to for the username (user#serverName).
I created variables and an f-string and then it worked OK.
import sqlalchemy
username = 'user#server_name'
password = 'PassWord!'
host = 'server_name.postgres.database.azure.com'
database = 'your_database'
conn_str = f'postgresql+psycopg2://{username}:{password}#{host}/{database}'
After that:
engine = sqlalchemy.create_engine(conn_str, pool_pre_ping=True)
conn = engine.connect()
Test it with a simple SQL statement.
sql = 'SELECT * FROM public.some_table;'
results = conn.engine.execute(sql)
This was a connection in UK South. Before that it did complain about the format of the username having to use #, although the username was correct, as tested from the command line with PSQL and another SQL client.

Cannot create direct connection to Oracle Server (Excel)

Hi I'm attempting to use some of the SQL code I've written in SQL developer through a direct database connection via Excel. Unfortunately the error message I receive whenever I try is:
"Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed."
I've painstakingly installed the Oracle 64bit client on my PC, so that at least, should be working. Unfortunately I've spent the best part of two days looking up solutions on the internet with no success. Does anyone know how I can force Excel to use my 64bit client or avoid this error in another way?
Update:
I believe despite my best efforts the problem is somewhere within my TNSNAMES file since I can't connect using SQL Plus either. Here's a redacted version of my Connection string. The ommitted details are correct since they are the same as I'm using for SQL Developer. Am I missing something?
DB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA = (SID = SID1)(SERVER = DEDICATED)
)
)
DB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA = (SID = SID2)(SERVER = DEDICATED)
)
)
Obviously, it's something small in your machine settings or configuration.
I would suggest you will look at your machine's PATH environment variable. It may refer to an older version of Oracle Server or the Oracle Client Components.
Make sure you know what you are using to access Oracle from Excel, JDBC or ODBC?
It's always the little details which drive us crazy.
Did you see any of these answers?
SQL Server 2012 connectivity to Oracle
Getting MS Office 2013 (32 bit) Excel and Access to connect to Oracle database when both 32 and 64 clients are installed
and I found this link, too complicated to copy everything to the answer:
Connect To Oracle Via ODBC Driver
And you can try connecting to Oracle with ODBC using ODAC or Oracle client, download ODAC112030_x64.zip from Oracle's website. Here's a link on how to install it SETTING UP AN ORACLE ODBC DRIVER AND DATA SOURCE

ORA:12154 error in Excel 2007

I have an excel file which was developed by my predecessor and which uses external data connection to fetch data from Oracle.
I am trying to migrate this file to a new client PC and I am getting the following error while refreshing the data:
ora 12154 tns could not resolve the connect identifier specified
The connection is established via DSN and TNS reference. The system specifications are as:
OS: Windows 7 64 bit
Oracle Client: Oracle 10.2.0 32 bit.
DSN Created in the 32 bit odbcad32.exe
TNSNames.ora is as under:
ODS_BKUP = (DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.146.64.132)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ODSDB)
) )
I am able to do Test connection succesfully from the DSN. TNS ping also working for the server. But when I refresh the data in excel, I am getting the error.
Connection String Given in excel
DSN=MP_Prod;UID=ODS_MPMON;PWD=ODS_MPMON;DBQ=ODS_BKUP;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BAM=IfAllSuccessful;NUM
What am I missing?
same problem here and this is the solution:
https://community.spiceworks.com/topic/277836-excel-2010-ora-12154-tns-could-not-resolve-service-name
Hope this help you! =)
Ale.

Error creating connection to Oracle ODBC in Excel

I am trying to connect to Oracle ODBC for OraClient10g_home1 in System DSN.once done,i have tested the connection and it says connection successful.but when i try to import Oracle data from Excel's built-in function (Microsoft Query),it gives me the following error message.please let me know how to fix this issue.
Oracle Database Server - 32 Bit,Operating System - Windows 10(64-Bit),Excel Office 2010 (32-Bit)
in tnsnames.ora you should have an entry for database instance located in target server like :
Test=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST=target server)(PORT=1521))
)
(CONNECT_DATA =
(SID = orcl)
)
)
then tnsping Test in cmd should work fine. you will use this tns entry in your odbc.

Resources