C# - Oracle Connectivity - oracle

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
);
}

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

Query Oracle using .net core throws exception for Connect Identifier

I'm quite new to Oracle and never used that before, now, I'm trying to query an Oracle database from a .Net Core Web Application having nuget package oracle.manageddataaccess.core installed and using an alias as the Data Source but I'm receiving the following error:
If I use the full connection string the query will work correctly
ORA-12154: TNS:could not resolve the connect identifier specified
at OracleInternal.Network.AddressResolution..ctor(String TNSAlias, SqlNetOraConfig SNOConfig, Hashtable ObTnsHT, String instanceName, ConnectionOption CO)
at OracleInternal.Network.OracleCommunication.Resolve(String tnsAlias, ConnectionOption& CO)
at OracleInternal.ConnectionPool.PoolManager`3.ResolveTnsAlias(ConnectionString cs, Object OC)
at OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, OracleConnection connRefForCriteria, String instanceName)
So, from a few links I could understand that there is a tsnnames.ora file which must contain the map between connect identifiers and connect descriptors. And that this file can be found at the machine on which the Oracle has been installed with the path ORACLE_HOME\network\admin.
Question is:
Does the alias name that I'm using in my connection string which reads as Data Source: <alias_name>; User ID=<user>; Password=<password> need to be specified in the tsnnames.ora file? I don't have access to the machine where the Oracle database resides on otherwise I would have checked it earlier.
Here's the code snippet for more info: connection string and query values are mocked out
public static string Read()
{
const string connectionString = "Data Source=TestData;User ID=User1;Password=Pass1";
const string query = "select xyz from myTable";
string result;
using (var connection = new OracleConnection(connectionString))
{
try
{
connection.Open();
var command = new OracleCommand(query) { Connection = connection, CommandType = CommandType.Text };
OracleDataReader reader = command.ExecuteReader();
reader.Read();
result = reader.GetString(0);
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
return result;
}
Is this enough or something else needs to be added/changed in here? Or probably the issue is with the tsnNames.ora file which might not contain the alias name here?
Thanks in advance
For the Data source
Data Source=TestData;User Id=myUsername;Password=myPassword;
Your tnsnames.ora probably should have the below entry
TestData=(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost) (PORT=MyPort)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)))
Since
Data Source=TestData;User Id=myUsername;Password=myPassword;
is same as
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost) (PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

Google Apps Jdbc - Connection Issue

I am trying to connect to a MySQL server using Jdbc for Google Apps and getting an error as follows:
Failed to establish a database connection. Check connection string,
username and password. (line 10, file "dbadmin")
The following is a snipet of the code I am using:
var address = 'w.x.y.z';
var user = 'user';
var userPwd = 'password';
var db = 'dbname';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
var conn = Jdbc.getConnection(dbUrl, user, userPwd);
I have successfully connected to the Database from my own computer using both the IP and Hostname. I have confirmed the server should be accepted connections from ALL IPs for that account, and confirmed the ruleset is working by removing the whitelisting and adding it back again.
I am basically out of troubleshooting ideas of what is going on. What am I doing wrong, or what is wrong with Google?
A typical way to establish JDBC connection is as follows:
String url = "jdbc:mysql://hostname:3306/mydb";
String username = "username";
String password = "password"
Connection conn = DriverManager.getConnection(url, username, password);
You can refer to this for more detailed information.

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

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)

Resources