Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2004, 07:28 PM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Right way in Handling ADONet in Window Forms

It has been a Common practice in VB6 Client/Server to maintain a Live
Data Connection thru out the lifetime of an application. Now in VBNet
Era, we are told to use Disconnected Data 'Coz Live Data Connection
Takes up valuable system resources and difficult to scale up).

Please enlighten on how to tackle this situation:
I have Client/Server Windows Application with Atleast 10
workstations and Each work station Open/Close
several Master-Details Windows Form but maintains atleast 5 at
a Time (Insert/Update/Delete).

Question:
1. Does Disconnected Data mean that I must Open and Close
     Connection in every Form?
     If Yes, If a User opens atleast 5 Windows Forms, Is safe to
             say that I open a Connection for each one?

            Will Connecting/Disconnecting to DataServer consume
            lesser system resources? How about the network traffic?

            Is this the way to do Disconnected Data?
            (OpenConn - Make Dataset - CloseConn- Add/Edit/Delete
            1 Record - Update the EditedRecord) or
            (OpenConn - Make Dataset - CloseConn-Add/Edit/Delete
            Records - Update Method)

     If No,How do I do it then


Proud To Be Pinoy
__________________
Proud To Be Pinoy
 
Old July 11th, 2004, 07:37 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Don't get confused by the term "disconnected data". What this means is that a data bound control (like a datagrid) is working against a snapshot of the data. You go out, take a snapshot and close the data connection, then use that disconnected data as the control's data source. This removes the overhead of a constantly open connection.

This technique being promoted is one that some call the 3G Bankrobber rule: Get in, Get what you want, Get out. What this means for your multi form situation is that you should open the data connection, get the data you want and close the data connection within the code that is getting the data. Even though you might have 5 or 50 forms open, you don't have any data connections open until you actually perform some data retrieval action. As soon as you perform an action that requires some data, you call a method that performs the 3 steps (open, get data, close).
 
Old July 11th, 2004, 07:39 PM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this the way to do Disconnected Dataset? Please Comment if there is something wrong with my code

Public Function OpenRs(ByVal DataSource As String, ByVal strSQL As String, ByVal ConnString As String) As DataSet
'Single DataSource
   Try
     Dim LiveConn As New SqlConnection(ConnString)
     Dim PDataset As DataSet
     Dim PCmd As New SqlCommand(strSQL, LiveConn)
     varSingleDA = New SqlDataAdapter(PCmd)
     Dim pCmdBldr As New SqlCommandBuilder(varSingleDA)
     PDataset = New DataSet()
     Me.varSingleDA.Fill(PDataset, DataSource)
     'LiveConn.Close() '1. Do I have to Close & Dispose liveconn to Have Disconnected Data? Why Am i having a hard time Updating when LiveConn is Closed and Disposed?

     'LiveConn.Dispose()

     'varSingleDA.Dispose() '2
     Return PDataset

     RaiseEvent TransactionCompleted(True)
   Catch err As SqlException
     MsgBox(err.Message)
     RaiseEvent TransactionCompleted(False)
   Catch err As Exception
     MsgBox(err.Message)
     RaiseEvent TransactionCompleted(False)
   End Try
End Function

Public Sub UpdateDataSet(ByVal VarDataset As DataSet, ByVal DataSource As String)
'Single DataSource
    Try
        If (Me.varSingleDA Is Nothing) Then
        Exit sub
            'OpenRsrs ??? 2. if i dispose varSingleDA in OpenRs should I Open it Here? Is disposing tha adaptor part of Disconnected data Trick?
        End If
        VarDataset.EnforceConstraints = False
        Me.varSingleDA.Update(VarDataset, DataSource)
        RaiseEvent TransactionCompleted(True)
    Catch err As SqlException
        MsgBox(err.Message)
        RaiseEvent TransactionCompleted(False)
    Catch err As Exception
        MsgBox(err.Message)
        RaiseEvent TransactionCompleted(False)
    End Try
End Sub

Please help me with this, I am confused with this new technology


Proud To Be Pinoy





Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering Popup window & Blur Parent window jkusmanto Javascript How-To 0 May 25th, 2007 03:19 AM
Can command prompt show in window forms? g0dchild_85 C# 0 June 26th, 2006 09:04 PM
Working with Forms and Popup window in Javascritp danieljava JSP Basics 0 November 20th, 2005 09:57 PM
Handling Events on Inherited Forms phil_kenney VB.NET 2002/2003 Basics 0 January 18th, 2005 11:34 AM
Handling window unload event MurthyGarimella Javascript 2 June 30th, 2004 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.