sys_debug
sys_debug

Reputation: 4003

oracle database connection in web.config asp.net

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.

Upvotes: 16

Views: 82682

Answers (3)

Nico de Wit
Nico de Wit

Reputation: 73

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.

Upvotes: 3

Josh Leeder
Josh Leeder

Reputation: 597

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"/>

Upvotes: 29

user2110717
user2110717

Reputation: 269

It may can help u....

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

http://www.connectionstrings.com/oracle

You can investigate what the connection string should be like:

1) Create an empty text file in windows explorer and rename it to X.UDL
2) Double click on it and the datalink provider dialog will appear.
3) Select the provider tab. Find the provider for your data access method and click next.
4) Select your source
5) Test the connection and save it.
6) Compare the contents of X.UDL with your connections string.

Upvotes: 0

Related Questions