Results 1 to 3 of 3

Thread: [2005] Should I be using COM ADO in VB.Net?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Question [2005] Should I be using COM ADO in VB.Net?

    I've had little time to learn VB.Net and am struggling with the new methods of connecting to databases. I have just found that if I include a reference to the "Microsoft ActiveX Data Objects 2.8 Library" COM object - just as I would have done in VB6 - I can use a lot of my old VB6 code with just minor changes.

    The question is: Am I handicapping myself by doing things this way? Are these old COM objects still supported in VB2008?

    Here's an example of my standard db connection module, modified very slightly to work in VB2005:

    Code:
    Module Module1
    
        Public GcnCon As ADODB.Connection
        Public GrsRec As ADODB.Recordset
        Public GsDBpath As String
    
        Sub Open_DB(ByVal SQL As String)
    
            Try
    
                GcnCon = New ADODB.Connection
                GcnCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & GsDBpath
                GcnCon.Open()
    
                GrsRec = New ADODB.Recordset
                GrsRec.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    
                GrsRec.Open(SQL, GcnCon, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockPessimistic)
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
        End Sub
    
        Sub Close_ADO()
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject(GcnCon)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(GrsRec)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    
    End Module
    I then call this sub with something like:

    GsDBpath = "n:\mydata.mdb"
    Call Open_db("Select * from tblCustomers")
    and then
    Call Close_ADO
    when I'm finished with the db.

    Any reason why I shouldn't do this in VB.Net?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] Should I be using COM ADO in VB.Net?

    You may not be handicapping your program, but you are handicapping yourself. I don't know whether COM ADO is faster or slower than ADO.NET, but it is fairly certain that eventually it will go away. I can understand wanting to leverage past understanding, but doesn't that ultimately limit you?
    My usual boring signature: Nothing

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Should I be using COM ADO in VB.Net?

    Using COM in .NET apps is always going to introduce an overhead. If you know ADO and not ADO.NET and you need to get something out right now then I'd say use ADO. Otherwise, why are you using VB.NET at all if you're just going to write VB6 code anyway? If you're going to use .NET then you should use .NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width