Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issue in Connecting to Oracle Database Using Python with cx_oracle

krishnabharatApr 27 2020 — edited May 12 2020

I am using cx_oracle to connect the Oracle DB using python.I need your assistance in connecting DB. I'm using following code till date it worked well

Code-1:

import cx_Oracle as cx dsn_tns = cx.makedsn(HOST,PORT, service_name=SERVICE_NAME)

conn = cx.connect(user=USER, password=PW, dsn=dsn_tns)

Recently TCP port is disabled and we are using jdbc connection string to connect DB which has TCPS port number.can you help where I need to pass the protocol in above/ suggest any other method.

i tried following code

code-2:

dsn_tns='(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = tcps)(HOST =hostdetails)(PORT =port))) (CONNECT_DATA = (SERVICE_NAME = servicename)))' conn = cx.connect(user=USER, password=PW, dsn=dsn_tns) print(cx.version)

I got error: ORA-28759: failure to open file.

Any suggestion is appreciated. Thank you in advance.

Comments

285751
Try adding a parameter 0 before your oraParmSessionID parameter. That will give the function someplace to return its result.

OraParameter oraReturn = new OraParameter();
oraReturn.ParameterName = "justaboutanything";
oraReturn.OraDbType = OraDbType.Date;
oraReturn.Direction = ParameterDirection.ReturnValue;
oraCommand.Parameters.Add(oraReturn );




Any ideas as to what's causing the following error:
---
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Oracle.DataAccess.Client.OraException:
/---
I'm simply calling an Oracle function which returns a date. Code snippet:
---
FUNCTION func_get_session_date(v_session_id VARCHAR2, v_session_key VARCHAR2) RETURN DATE IS
...etc
/---
...employing the OraDataReader to extract the value (unnecessary code extracted for clarity):
---
DateTime returnDateTime;
string commandText = "SELECT pkg_css_session_state.func_get_session_date(:v_session_id, :v_session_key) FROM dual";
//string commandText = "SELECT pkg_css_session_state.func_get_session_date('" + this.AspxSessionID + "', '" + sessionKey + "') FROM dual";
OraConnection oraConnection = new OraConnection(connectionString);
OraCommand oraCommand = new OraCommand();
oraCommand.Connection = oraConnection;
oraCommand.CommandText = commandText;
OraParameter oraParmSessionID = new OraParameter();
oraParmSessionID.ParameterName = "v_session_id";
oraParmSessionID.OraDbType = OraDbType.Varchar2;
oraParmSessionID.Value = this.AspxSessionID;
oraParmSessionID.Direction = ParameterDirection.Input;
oraCommand.Parameters.Add(oraParmSessionID);
OraParameter oraParmSessionKey = new OraParameter();
oraParmSessionKey.ParameterName = "v_session_key";
oraParmSessionKey.OraDbType = OraDbType.Varchar2;
oraParmSessionKey.Value = sessionKey;
oraParmSessionKey.Direction = ParameterDirection.Input;
oraCommand.Parameters.Add(oraParmSessionKey);
oraConnection.Open();
OraDataReader oraDataReader = oraCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (oraDataReader.Read())
{
if (! oraDataReader.IsDBNull(0))
{
returnDateTime = oraDataReader.GetDateTime(0);
}
}
/--
Interestingly, it works fine when I don't use input parameters (see commented-out commandText string).
Thanks ahead o' time!
1 - 1

Post Details

Added on Apr 27 2020
19 comments
4,317 views