|
-
Feb 3rd, 2008, 10:44 AM
#1
Thread Starter
Fanatic Member
[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?
-
Feb 3rd, 2008, 10:58 AM
#2
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
 
-
Feb 3rd, 2008, 05:37 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|