Logo 
Search:

Asp.net Articles

Submit Article
Home » Articles » Asp.net » DatabaseRSS Feeds

How to connect Oracle database in Asp.net

Posted By: Vivek Patel     Category: Asp.net     Views: 21291

This article will explains how to make oracle connection in asp.net code using c#

In order to connect oracle database from your asp.net application, you need to follow following steps.

1) Add reference of Oracle database client library.  

  • Right click on “Add Reference” inside your project.
  • From Add Reference dialog box click on “.Net” tab
  • Select “System.Data.OracleClient” from Component Name 
  • Click “OK” button to add reference.

2) Inside Web.Config File, Add connection string

<configuration>
  <connectionStrings>

<add name="ConnStr" 
connectionString="Data Source=<DB ServerName>;User ID=<SchemaName/UserName>;Password=<Password>;Persist Security Info=True;Connection Lifetime=10" providerName="System.Data.OracleClient"></add>

</configuration>
  </connectionStrings>

Now you are ready to make oracle connection
Add following function in your code file. 


3) Function to read oracle connection string from web.config file.

private OracleConnection GetConnection()
        {
            var conString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"];
            string strConnString = conString.ConnectionString;
            return new OracleConnection(strConnString);
        }

4) Call GetConnection function to use oracle connection in your code.

 //Sample code to open and close oracle connection
protected void Page_Load(object sender, EventArgs e)
        {
            OracleConnection oConn = GetConnection();

            if (oConn != null)
            {
                oConn.Open();
                oConn.Close();
            }
        }
  
Share: 


Didn't find what you were looking for? Find more on How to connect Oracle database in Asp.net Or get search suggestion and latest updates.

Vivek Patel
Vivek Patel author of How to connect Oracle database in Asp.net is from United States. Vivek Patel says

I have started working in .Net Technology since its beta release and lucky to got chance to work on .Net 1.1, 2.0 and now working on .Net 3.5. I have worked in both C# and VB.Net for Asp.net Projects. I can also provide Sharepoint development needs. I can efficiently switch role from Tech Lead and Developer. I have comprehensive knowledge of Asp.net Development. I have been award Microsoft Most Valuable Award twice in Asp.net Technology.

Blog: http://dotnetguts.blogspot.com

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Vipin Tyagi from India Comment on: Mar 25
Hey this is not fully describe how to connect with oracle

View All Comments