Skip to main content

Connected and disconnected architecture in ADO.Net with Example


Connected Architecture of ADO.NET
The architecture of ADO.net, in which connection must be opened to access the data retrieved from database is called as connected architecture. Connected architecture was built on the classes connection, command, datareader and transaction. 

Connected architecture is when you constantly make trips to the database for any CRUD (Create, Read, Update and Delete) operation you wish to do. This creates more traffic to the database but is normally much faster as you should be doing smaller transactions.
Disconnected Architecture in ADO.NET

The architecture of ADO.net in which data retrieved from database can be accessed even when connection to database was closed is called as disconnected architecture. Disconnected architecture of ADO.net was built on classes connection, dataadapter, commandbuilder and dataset and dataview.
Disconnected architecture is a method of retrieving a record set from the database and storing it giving you the ability to do many CRUD (Create, Read, Update and Delete) operations on the data in memory, then it can be re-synchronized with the database when reconnecting. A method of using disconnected architecture is using a Dataset.

DataReader is Connected Architecture since it keeps the connection open until all rows are fetched one by one
DataSet is DisConnected Architecture since all the records are brought at once and there is no need to keep the connection alive
Difference between Connected and disconnected architecture


Connected Disconnected
It is connection oriented.
It is dis_connection oriented.
Datareader DataSet
Connected methods gives faster performance
Disconnected get low in speed and performance.
connected can hold the data of single table disconnected can hold multiple tables of data
connected you need to use a read only forward only data reader
disconnected you cannot
Data Reader can't persist the data
Data Set can persist the data
It is Read only, we can't update the data.
We can update data

Example

Create Database “Student”

CREATE TABLE [dbo].[Student]
(
    [ID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
    [Name] [varchar](255) NULL,
    [Age] [int] NULL,
    [Address] [varchar](255) NULL
)

INSERT INTO Student([Name],[Age],[Address])VALUES('NAME 1','22','PUNE')
INSERT INTO Student([Name],[Age],[Address])VALUES('NAME 2','25','MUMBAI')
INSERT INTO Student([Name],[Age],[Address])VALUES('NAME 3','23','PUNE')
INSERT INTO Student([Name],[Age],[Address])VALUES('NAME 4','21','DELHI')
INSERT INTO Student([Name],[Age],[Address])VALUES('NAME 5','22','PUNE')

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Pagetitle>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CC9966"
            BorderStyle="None" BorderWidth="1px" CellPadding="4">
            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
            <RowStyle BackColor="White" ForeColor="#330099" />
            <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
        </asp:GridView>
        <br />
        <asp:Button ID="Connected" runat="server" OnClick="Connected_Click" Text="Connected" />
        <asp:Button ID="Disconnected" runat="server" EnableTheming="False" OnClick="Disconnected_Click"
            Text="Disconnected" />
    </div>
    </form>
</body>
</html>

Code Behind


String StrSQL = "", StrConnection = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            StrSQL = "SELECT * FROM Student";
            StrConnection = "Data Source=ServerName;Initial Catalog=Database;User ID=Username;Password=password";
        }

        protected void Connected_Click(object sender, EventArgs e)
        {
            using (SqlConnection objConn = new SqlConnection(StrConnection))
            {
                SqlCommand objCmd = new SqlCommand(StrSQL, objConn);
                objCmd.CommandType = CommandType.Text;
                objConn.Open();
                SqlDataReader objDr = objCmd.ExecuteReader();
                GridView1.DataSource = objDr;
                GridView1.DataBind();
                objConn.Close();
            }
        }

        protected void Disconnected_Click(object sender, EventArgs e)
        {
            SqlDataAdapter objDa = new SqlDataAdapter();
            DataSet objDs = new DataSet();
            using (SqlConnection objConn = new SqlConnection(StrConnection))
            {
                SqlCommand objCmd = new SqlCommand(StrSQL, objConn);
                objCmd.CommandType = CommandType.Text;
                objDa.SelectCommand = objCmd;
                objDa.Fill(objDs, "Student");
                GridView1.DataSource = objDs.Tables[0];
                GridView1.DataBind();
            }
        }




Download



Comments

  1. DataSet is disconnected and DataReader is connected. You can correct that inthe table.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Don't you think we use DataAdapter in connected architecture?

    ReplyDelete
  5. Hi,
    • SqlDataAdapter can work with disconnected and connected architecture ,
    • SqlDataAdapter can directly update the DB(for instance change in datagridview can directly reflect database table) if used with SqlCommandBuilder
    • SqlDataAdapter can fill DataTable,DataSet
    • Sqlcommand can use Command.Executereader to read the data(which has better performance then Fill method of DataAdapter)

    We can use data adapter in Connected architecture as below
    Example


    SqlDataAdapter objDa;
    DataTable dt;
    using (SqlConnection objConn = new SqlConnection(StrConnection))
    {
    SqlCommand objCmd = new SqlCommand(StrSQL, objConn);
    objConn.Open();
    objDa = new SqlDataAdapter(objCmd);
    dt = new DataTable();
    objDa.Fill(dt);
    GridView1.DataSource = dt;
    GridView1.DataBind();
    objConn.Close();
    }

    ReplyDelete
  6. • SqlDataAdapter can work with disconnected and connected architecture ,

    this line is true ???????

    ReplyDelete
  7. Hi Rahul

    This is Saravanan, the notes and example which u posted is very much use full for me. Thank's a lot

    Regards
    Saravanan.S

    ReplyDelete
  8. in ASP.net projects, when we use Connected & disconnected model

    i.e Command & DataAdapter to update data

    Regards
    Sreenivas

    ReplyDelete
  9. Use Connected model when:

    • For large / huge amount of data.
    • The data is getting changed very frequently

    Use Disconnected model when:

    • The data is small /less
    • It is not changing frequently or the application can handle the changes nevertheless.
    • Frequent query to database is either not possible or perhaps is time/resource consuming.

    ReplyDelete
  10. thanks for very useful information........

    ReplyDelete
  11. Thank you for useful information given in Help To Understand.Net

    ReplyDelete
  12. hi, Thanks for Sharing this Valuable Information.
    .Net Training in Delhi

    ReplyDelete
  13. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  14. Data reader is a disconnected architecture component?

    ReplyDelete
  15. Thanks for a marvelous posting! I seriously enjoyed reading it, you are
    a great author.I will be sure to bookmark your blog and will often come back in the future.
    I want to encourage yourself to continue your great job, have a
    nice weekend!
    java training in chennai

    java training in velachery

    aws training in chennai

    aws training in velachery

    python training in chennai

    python training in velachery

    selenium training in chennai

    selenium training in velachery

    ReplyDelete
  16. This post is usefull and informative.Keep Updating with more infomration...
    Learning The German Language
    Benefits Of Learning German Language

    ReplyDelete
  17. This post is so useful and informative keep updating with more information.....
    Data Science Overview
    Data Science Courses Eligibility

    ReplyDelete
  18. Great Post!!! Thanks for sharing this post ans i am waiting for the new data updates.
    How To Grow Business With Digital Marketing?
    Grow Business with Digital Marketing

    ReplyDelete
  19. Thank you for a fantastic post! I thoroughly enjoyed reading it; you are an excellent author. I will read your blog and return frequently in the future.
    I'd like to encourage you to keep up the good work. also I done my web development course in kolkata .
    once again thanks for sharing ...

    ReplyDelete
  20. Hey author this is really very good article . and currently I'm also doing Web Design Course In Kolkata . I'm grateful that you shared this fantastic information with us. I found this information to be of great value. This article has increased my knowledge even more.
    Thank you ...

    ReplyDelete
  21. Nice information. Found something new to learn here.
    Learn online networking and cybersecurity courses here:
    Online Fortinet Training
    Online CCNA Training

    ReplyDelete
  22. In ADO.NET, developers can choose between two architectural approaches: connected architecture and disconnected architecture. These approaches determine how the application interacts with the database and manages data.

    The connected architecture in ADO.NET involves establishing a continuous connection to the database throughout the application's lifespan. In this approach, the application maintains an open connection to the database, executes queries, Best cameras for streaming, retrieves data, and updates the database in real-time. Any changes made to the data are immediately reflected in the database, and the application can access the latest information.

    On the other hand, the disconnected architecture in ADO.NET operates in a disconnected manner. The application establishes a connection to the database only when necessary, retrieves data, and then disconnects from the database. The retrieved data is stored locally in datasets or data tables, allowing the application to work with the data without maintaining a continuous connection to the database. Once the required operations are completed, the application can reconnect to the database to update the changes.

    To illustrate this concept, let's consider a commenting website as an example. In the connected architecture, the application establishes a connection to the database at the start and keeps it open throughout the user's session. Whenever a user submits a comment or interacts with the website, best cameras for video, the application directly inserts or updates the data in the database, reflecting the changes immediately. This architecture ensures real-time synchronization between the application and the database.

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Recently I saw your blog, thanks for the information. Internet Marketing

    ReplyDelete

Post a Comment

Popular posts from this blog

HTTPHandler and HTTPModule in ASP.NET

If you want to implement pre-processing logic before a request hits the IIS resources. For instance you would like to apply security mechanism, URL rewriting, filter something in the request, etc. ASP.NET has provided two types of interception HttpModule and HttpHandler .   The web server examines the file name extension of the requested file, and determines which ISAPI extension should handle the request. Then the request is passed to the appropriate ISAPI extension.  For Example When an .aspx page is requested it is passed to ASP.Net page handler. Then Application domain is created and after that different ASP.Net objects like Httpcontext, HttpRequest, HttpResponse. HTTPModule: -    It's just like a filter. The Modules are called before and after the handler executes . -    HTTP Modules are objects which also participate the pipeline but they work before and after the HTTP Handler does its job, and produce additional services within the pipeline -  

ASP.NET Page Life Cycle with example

In this article, we are going to discuss the different methods and order they are executed during the load of an .aspx web page. Methods Description Page_PreInit Before page Initialization Page_Init Page Initialization LoadViewState View State Loading LoadPostData Postback Data Processing Page_Load Page Loading RaisePostDataChangedEvent PostBack Change Notification RaisePostBackEvent PostBack Event Handling Page_PreRender Page Pre Rendering Phase SaveViewState View State Saving Page_Render Page Rendering Page_Unload Page Unloading PreInit : The entry point of the page life cycle is the pre-initialization phase called “PreInit”. You can dynamically set the values of master pages and themes in this event. You can also dynamically create controls in this event.  Init : This event fires after each control h