I am not able to connect to Oracle XE database in another system? - oracle

I have used this code to connect to XE database:
OracleConnection con = new OracleConnection();
con.ConnectionString = "data source=XE;user id=hr;password=sdmo1365";
con.Open();
OracleCommand com = new OracleCommand();
com.CommandText = "select * from regions;";
com.Connection = con;
DataTable dt = new DataTable();
dt.Load(com.ExecuteReader());
con.Close();
grd.DataSource = dt;
grd.DataBind();
it is working in one pc while not working in another and giving this error:
oracleexception was unhandled by user code
the only difference in tnsnames.ora of those pc is in the one that is not working the host is longer(becuase the user is under domain:)
(HOST = MOSININI-9.novini.mms.sti)
is this making the problem?
thanks

I simply reinstalled it and everything get solved!(I waste 2 hours)

Related

Not able to connect to Oracle DB through Wallet from C#

I am trying to connect to the Vendor's database through the Wallet. For that, the vendor has provided a wallet zip files which contains two files (one .ora file and one .sso file) . The zip file contains tnsnames.ora and cwallet.sso
First, I installed the Oracle client version 19.0 Home1 which has created a file called sqlnet.ora automatically. I copied the file tnsnames.ora to the same folder where sqlnet.ora created, and tried different wasys to connect the database, but every attempt failed. I tried to implement in similar way which is explained in this link, but getting errors that "TNS:Lost contact", "TNS:Could not resolved the connect identifier specified".
I tried the solution which specified here, but ended up in error. Finally, the error now is "Connection failed because target host or object does not exist". The connection details are specified in tnsnames. ora that contains the service name and host name. I have added the Wallet location in sqlnet.ora file and also the following code:
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 1.2
SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_CBC_SHA)
SSL_SERVER_DN_MATCH = ON
The connection code in C# is below:
//string strCon = "User Id =XXXX;Password=XXXXXXX;Data Source=(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST=XXXXXXXX)(PORT=2460))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX))" +
// "(SECURITY=(SSL_SERVER_CERT_DN='C=US,ST=Washington,L=Seattle,O=Amazon.com,OU=RDS,CN=mcsldb01.ckc6ued9hacf.ap-south1.rds.amazonaws.com')));";
using (OracleConnection con = new OracleConnection(strCon))
//using (OracleConnection con = new OracleConnection(#"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=XXXXXXXX)(PORT=2460)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX)));User Id=XXXX;Password=XXXXXXXX;"))
//using (OracleConnection con = new OracleConnection(cntn))
{
using (OracleCommand cmd = con.CreateCommand())
{
try
{
//TNS_ADMIN and wallet directory entries can be entered in the app.config file.
con.Open();
Console.WriteLine("Successfully connected to Oracle Autonomous Database");
//Retrieve database version info
cmd.CommandText = "SELECT BANNER FROM V$VERSION";
OracleDataReader reader = cmd.ExecuteReader();
reader.Read();
Console.WriteLine("Connected to " + reader.GetString(0));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
Please suggest any solution. Where I am going wrong? Not able to proceed further.
At a guess, it might have been a connection wallet not an SSL wallet that has been provided, ie, just a mechanism of hiding the username and password. If that is the case, the connection would look something like:
new OracleConnection(#"Data Source=NAME_IN_TNSNAMES;User Id=/"))
where NAME_IN_TNSNAMES maps to the entry in the tnsnames.ora file.
Examples of that (from a SQL Plus perspective) here
https://connor-mcdonald.com/2015/09/21/connection-shortcuts-with-a-wallet/

The provider is not compatible with the version of oracle (ASP.NET Core MVC)

I'm really frustrated and i do not know what to do.
I'm trying to connect to an Oracle 11g database but every time I try to connect Visual Studio 2019 throws an error message. I already tried a lot of different things but nothing really helped me.
I have already made sure the app set to run in 32 bit mode in the IIS console. I still can't figure out why is not working.
By the way, here is my code:
readonly string connectionString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxxxxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=PROD)));User Id=xxx;Password=xxxx;"
public IEnumerable<Person>GetPersonList
{
var listPerson = new List<Person>();
using (OracleConnection con = new OracleConnection(connectionString))
{
OracleCommand cmd = new OracleCommand("select * from myview", con);
cmd.Connection = con;
cmd.InitialLOBFetchSize = 1000;
cmd.CommandType = CommandType.Text;
con.Open();
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
var list = new Person();
list.CODE = Convert.ToInt32(dr["CODE"].ToString());
list.NAME = dr["NAME"].ToString();
list.LASTNAME = dr["LASTNAME"].ToString();
listPerson.Add(list);
}
con.Close();
}
return listPerson;
}
What should I do?
My problem was solved: needed to install instant client for Oracle 11g and everything worked just fine

Glassfish JDBC lookup jindi

I created a "JDBC Connection Pools" and a "JDBC Resources" called myDB (JINDI name).
How to access this in my webapp?
I tried:
<ejb-ref>
<ejb-ref-name>myDB</ejb-ref-name>
<lookup-name>myDB</lookup-name>
</ejb-ref>
And how to access it in the code?
I tried:
InitialContext ctx = new InitialContext();
com.sun.appserv.jdbc.DataSource ds = (com.sun.appserv.jdbc.DataSource) ctx.lookup("jdbc/myDB");
Connection con = ds.getConnection();
Connection drivercon = ds.getConnection(con); //get physical connection from wrapper
Statement stmt=null;
stmt = con.createStatement();
stmt.executeUpdate("Update");
// Do db operations.
// Do not close driver connection.
stmt.close();
con.close(); // return wrapped connection to pool.
Or like this?
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/myDB?"
+ "user=admin&password=admin");
I am irritated. I just want to access my relational db to select and insert things.

C# - Oracle Connectivity

My connection is failing with the following message: "The procedure entry point ons_subscriber_cancelcallback could not be located in the dynamic link library oraons.dll".
Can anyone please help ?
The code is pretty straight forward:
string oradb = "";
oradb = "Data Source=MYORADB;Password=MYPASS123;User ID=MYUSERID;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
I have already connected TOAD with these credentials.
For me, the solution was to go to the Oracle website where I downloaded and installed the latest version of the Oracle Data Access Components (ODAC).
You'll want to be careful to install the correct version for your programming environment. In my case, it was version 12c (64-bit).
From there, I redirected the Oracle.DataAccess.dll reference to the version that I'd just installed.
You don't seem to have a database IP or port number there. Once you have those available, try using the Oracle EZCONNECT format:
//Check that MYORADB is your actual SID number
string oradb = getConnectionString("10.1.2.3", 1521, "MYORADB", "MYUSERID", "MYPASS123");
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
private static string getConnectionString(string databaseIP, int databasePort, string databaseSID, string databaseUN, string databasePW)
{
return string.Format(
"Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1}))(CONNECT_DATA =(SID = {2})));" +
"Persist Security Info=True;User ID={3};Password={4}",
databaseIP, databasePort, databaseSID, databaseUN, databasePW
);
}

Oracle and Transaction naming

I've been programing with SQL Server and C# for quite some time and I have some code that I need to change to work with Oracle:
SqlConnection connection = (SqlConnection)CreateDBConnection();
IDbTransaction transaction = connection.BeginTransaction(level, "name");
The problem is: if I use OracleConnection instead of SqlConnection there is no way to specify a name for my transaction. I know that the syntax in Oracle allows named transactions, but I don't seem to find a way to do it through .net code.
You can not set the transaction name.
But it is possible to specify a name for the SAVEPOINT.
OracleConnection oracleConnection = new OracleConnection((string.Format("Data Source={0};User Id={1};Password={2}", DATABASE, USERNAME, PASSWORD));
oracleConnection.Open();
OracleCommand oracleCommand = oracleConnection.CreateCommand();
oracleConnection.BeginTransaction();
OracleTransaction oracleTransaction = oracleCommand.Transaction;
oracleTransaction.Save("name");
//...
oracleTransaction.Rollback("name");

Resources