ASP.NET
  Home arrow ASP.NET arrow Page 5 - Connecting to Different Databases Using AS...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Connecting to Different Databases Using ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 18
    2006-10-09

    Table of Contents:
  • Connecting to Different Databases Using ASP.NET 2.0
  • Connecting to Microsoft SQL Server database using the database class: source code
  • Connecting to Microsoft SQL Server database using the SqlDatabase class
  • Connecting to Microsoft SQL Server database using the GenericDatabase class
  • Connecting to an Oracle database using the GenericDatabase class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Connecting to Different Databases Using ASP.NET 2.0 - Connecting to an Oracle database using the GenericDatabase class


    (Page 5 of 5 )

    The previous section concentrated on using the GenericDatabase class to connect and work with Microsoft SQL Server.  In this section, I shall continue with the same class and work with Oracle databases.

    Before you begin, modify your web.config as following:

    <configuration>

          <appSettings/>

          <connectionStrings>

                <!--<add name="AdventureWorks"
    connectionString="Database=AdventureWorks;Server=(local)
    SQL2k5;Integrated Security=SSPI;"
    providerName="System.Data.SqlClient"/>
    -->

                <add name="MyOracleDB" connectionString= "Provider=msdaora;Data
    Source=MyOracleDB;User Id=UserName;Password=asdasd;"
     />

          </connectionStrings>

    The following code uses the GenericDatabase class to connect to a Microsoft SQL Server database using OLEDB connection string.

    ImportsSystem.Data

    ImportsMicrosoft.Practices.EnterpriseLibrary.Data

    PartialClass _Default

        Inherits System.Web.UI.Page

        Protected Sub btnConnect_Click(ByVal sender As Object, ByVal
    e As System.EventArgs) Handles btnConnect.Click

            Dim db As New GenericDatabase
    (ConfigurationManager.ConnectionStrings
    ("MyOracleDB").ConnectionString,
    System.Data.OleDb.OleDbFactory.Instance)

            Me.lblMsg.Text = db.ConnectionStringWithoutCredentials

            Dim dt As DataTable = db.ExecuteDataSet(CommandType.Text,
    "select * from Scott.emp").Tables(0)

            Me.GridView1.DataSource = dt

            Me.GridView1.DataBind()

        End Sub

    EndClass

    Even though I used the GenericDatabase class to connect to Oracle, you can also connect using the OracleDatabase as follows:

            Dim db As OracleDatabase = DirectCast
    (DatabaseFactory.CreateDatabase("MyOracleDb"), OracleDatabase)

    It all depends on your needs.  In my upcoming contributions, we shall look into the most used routines in the Data Access Application Block (along with accessing stored procedures).  Don’t forget to check back or sign up for a newsletter to notify you!

    The entire source code for this article is available in the form of a downloadable zip. The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition together with Microsoft SQL Server 2005 Developer Edition and Microsoft Enterprise Library for .NET Framework 2.0 (January 2006 version). I didn’t really test the solution with any other/previous editions.  If you have any problems in executing the solution, please post in the discussion area.

    Any feedback, suggestions, bugs, errors, improvements etc., are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys. This is second in the series on working with Microsoft Enterprise...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT