Khurram Majeed Khurram Majeed - 1 year ago 790
C# Question

Connecting to Oracle using Oracle.ManagedDataAccess

I am using Oracle.ManagedDataAccess Nuget Package Version 12.1.022 in my C# (.NET 4.0) project. The package automatically creates entries in the app.config file. How can I read the datasource string from this file to be able to connect to the data base?


is not working for me

<?xml version="1.0" encoding="utf-8"?>

<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client"
description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<publisherPolicy apply="no" />
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion=" - 4.65535.65535.65535" newVersion="" />

<version number="*">
<dataSource alias="MyDataSource"

Answer Source

Typically, you would refer to the alias in a standard connection string:

    <add name="MyConnection" connectionString="Data Source=MyDataSource;User Id=scott;Password=tiger;"/>

Then you would use the standard method for retrieving the string:


Also keep in mind that the data source section is optional. You can embed the descriptor directly in the connection string:

    <add name="MyConnection" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=;User Id=scott;Password=tiger;"/>

You can also refer to aliases in a tnsnames.ora file. By default the driver looks for a tnsnames.ora in the exe folder, a directory specified in a TNS_ADMIN environment variable, or the TNS_ADMIN config variable:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download