Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle database connection in web.config asp.net

Tags:

c#

asp.net

oracle

I know I can create a connection string in the c# class itself, but I am trying to avoid doing that. I want to create the connection in the web.config, which I read is more secure. Nevertheless I couldn't find any example that has the following attributes specified:

  • Host name
  • Port
  • SID
  • Username
  • Password
  • Connection Name

Could anyone help please with creating this in webconfig? I am connecting to oracle DB.

like image 768
sys_debug Avatar asked May 08 '13 04:05

sys_debug


People also ask

Can we use Oracle with ASP NET?

Oracle Developer Tools for Visual Studio is a tightly integrated "add-in" for Visual Studio. This tight integration makes it easy to create ASP.NET Web Applications that access Oracle database without requiring the developer write much code.

What is TNS ORA file in Oracle?

The tnsnames.ora file is a configuration file that defines connection parameters for your Oracle database instance. By default, tnsnames.ora resides in the following location: Solaris. Oracle_HOME/network/admin. Windows.


2 Answers

Here is the template:

     <connectionStrings>
        <add name="{ConnectionName}" 
        connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;" 
        providerName="Oracle.DataAccess.Client"/>
     </connectionStrings>

Here is one of mine - minus a real TNS name and username and password:

    <add name="MSOL" connectionString="Data Source={TNS_NAME};User ID={username};Password={password};pooling=true;min pool size=5;Max Pool Size=60" providerName="Oracle.DataAccess.Client"/>
like image 65
Josh Leeder Avatar answered Oct 06 '22 03:10

Josh Leeder


After adding the connection string to the web.config you can use the following:

System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

to retrieve the connection string.

like image 40
Nico de Wit Avatar answered Oct 06 '22 02:10

Nico de Wit