Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

OracleConnection, web.config, ODP.NET, and ASP.NET / C#

wblacklJan 11 2008 — edited Jan 12 2008
I had a hard time finding this information on the web, so I decided to post it here for someone else. I was finding it difficult to locate information on the proper method to store the database username and password in the web.config file, but reference it in my C# code while using ODP.NET. The problem was how to get the OracleConnection to use the connectionString in the web.config file. The trick is to use the ConfigurationManager.ConnectionStrings. See below. I hope this is helpful. It may not be the best way to do it, but it seems to work.

void Login_Click(Object sender, EventArgs E)
{


OracleConnection MyConn = new OracleConnection(ConfigurationManager.ConnectionStrings["oracle_db"].ConnectionString);
string strCommandText = "SELECT SYSDATE FROM DUAL;”
OracleCommand command = new OracleCommand(strCommandText);
command.Connection = MyConn;
MyConn.Open();
// application program code HERE //
MyConn.Close();
MyConn.Dispose();

}


<configuration>
<connectionStrings>
<add name="oracle_db"
connectionString="Data Source=tns_name; UserID=acct_name;Password=acct_passwd;" providerName="System.Data.OracleClient"/>
</connectionStrings>
</configuration>

Tns_name is the name you use to reference to oracle database in the tnsnames.ora file.
Acct_name is the database user login.
Acct_passwd is the database password.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 9 2008
Added on Jan 11 2008
1 comment
4,904 views