I'm trying to connect to ORACLE 10g database on Windows 7 64x version from C# Desktop application using Oracle.ManagedDataAccess.Client as SYSDBA.
here is my connection string from config file:
<add name="default" connectionString="User Id=scott;Password=tiger;DBA Privilege=SYSDBA;Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = sherif-PC)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =orcl2)));" providerName="Oracle.ManagedDataAccess.Client"/>
and here is the code:
ConnectionStringSettings ConnectString = ConfigurationManager.ConnectionStrings["default"];
_dbFact = DbProviderFactories.GetFactory(ConnectString.ProviderName);
_con = _dbFact.CreateConnection();
_con.ConnectionString = ConnectString.ConnectionString;
using (_con)
{
_con.Open();
using (_cmd = _con.CreateCommand())
{
_cmd.CommandText = "select * from EMP;";
using (IDataReader reader = _cmd.ExecuteReader())
{
res = reader.GetString(1);
}
}
_con.Close();
MessageBox.Show(res);
}
I must use DbProviderFactory as it must be general solution for different kind of dbs