Results 1 to 2 of 2

Thread: comparing load

  1. #1
    Join Date
    Oct 2004
    Location
    In cousin's house
    Posts
    303

    Lightbulb Unanswered: comparing load

    Procedure 1
    Private Sub Command3_Click()
    Dim cnn1 As ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim cmdByRoyalty As ADODB.Command
    Dim strCnn As String

    Set cnn1 = New ADODB.Connection
    strCnn = "Provider=sqloledb;" & _
    "Address=192.168.0.10;Initial Catalog=pubs;Trusted_connection=Yes;"
    cnn1.Open strCnn

    Set cmdByRoyalty = New ADODB.Command
    Set cmdByRoyalty.ActiveConnection = cnn1

    cmdByRoyalty.CommandText = "au_info"
    cmdByRoyalty.CommandType = adCmdStoredProc
    cmdByRoyalty.Parameters.Refresh
    cmdByRoyalty.Parameters(1) = Text1
    cmdByRoyalty.Parameters(2) = Text2
    Set rs = cmdByRoyalty.Execute()
    Set m.DataSource = rs
    rs.Close
    cnn1.Close
    End Sub

    Procedure 2
    Dim rs As New ADODB.Recordset
    Dim cmdByRoyalty As ADODB.Command
    Dim strCnn As String

    Private Sub Form_Load()
    Set cnn1 = New ADODB.Connection
    strCnn = "Provider=sqloledb;" & _
    "Address=192.168.0.10;Initial Catalog=pubs;Trusted_connection=Yes;"
    cnn1.Open strCnn
    End Sub
    Private Sub Form_unLoad()
    cnn1.close
    End Sub

    Private Sub Command3_Click()
    Set cmdByRoyalty = New ADODB.Command
    Set cmdByRoyalty.ActiveConnection = cnn1
    cmdByRoyalty.CommandText = "au_info"
    cmdByRoyalty.CommandType = adCmdStoredProc
    cmdByRoyalty.Parameters.Refresh
    cmdByRoyalty.Parameters(1) = Text1
    cmdByRoyalty.Parameters(2) = Text2
    Set rs = cmdByRoyalty.Execute()
    Set m.DataSource = rs
    rs.Close
    End Sub

    Any have idea on which procedure are better the procedure 1 or 2?
    In procedure 1 ,I only open the connection when there is transaction happen, then I close it. In procedure 2 I open the connection during form load. Comments,suggestion is highly appreciated.

    Thanks...

  2. #2
    Join Date
    Dec 2004
    Location
    Coon Rapids, Minnesota
    Posts
    41
    I initially used to always set up my ADODB connections at form load, just because I know I am going to be using them throughout my program, but more recently I have started making them into procedures to be called as and when I need them after learning more and more about making a program as efficient as possible. So I guess I think it is better to do it as and when you need it, but I am still somewhat new to VB and am probably not the most informed on this. Especially after someone recently had to inform me of how to use disconnected recordsets!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •