VB.Net - ADODB, trying to get ODBC Driver?

Soldato
Joined
4 Nov 2007
Posts
4,514
Code:
        Dim ConnectDB As New ADODB.Connection
        Dim ConnectRS As New ADODB.Connection
        Dim MyTable As String

        ConnectDB.Open("Provider=sqloledb;" & "Data Source=hbcsql3;" & "Initial Catalog=mailreader;" & "User Id=***;" & "Password=***;")

        MyTable = "select * from mail_info"
        ConnectRS.Open(MyTable, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1)

50156331bh2.png


Reeeeally need to avoid ODBC Drivers as it needs to be used by a mass amount of remote users. Does ADODB still work in VB.net? Been using VB6 till today, added the Microsoft ActiveX Database Object 2.7 reference.

Help.
 
What database?
From the connection string looks like it's SQL Server.

In which case you should have a look at the System.Data.SqlClient namespace
 
Yes it does work but the new ADO.Net is much better.
I think that using the COM object means you will be using ODBC anyway.

To get it working, check the System DSN for your connection rather than the User DSN.

If that's OK, is it running on a 64 bit OS? If it is you may find that you have to run
C:\Windows\SysWOW64\odbcad32.exe
to set up DNS for 32bit programs.

Simon
 
As the other posts say it does work but you should use ADO .NET if possible.

You have declared your connection and recordset as ADODB.Connection objects, this could be one reason for the error. It should be,

Dim ConnectDB As New ADODB.Connection
Dim ConnectRS As New ADODB.Recordset

Update...

Ive just tried it and that was part of the error, the other thing was that you had missed the connection object from the RS.open

Dim ConnectDB As New ADODB.Connection
Dim ConnectRS As New ADODB.Recordset
Dim MyTable As String

ConnectDB.Open("Provider=sqloledb;" & "Data Source=hbcsql3;" & "Initial Catalog=mailreader;" & "User Id=***;" & "Password=***;")

MyTable = "select * from mail_info"
ConnectRS.Open(MyTable, ConnectDB, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1)
 
Last edited:
Still getting same error on the same line, took the -1 out as .Open cannot handle that many arguments.

This is far too complex for me, I can probably do what I need with the data once I get a connection, anyone fancy giving me a hand and writing the connection string?
 
www.connectionstrings.com is always a good place to look.

This should do it both ways, have a read up on DataReaders/DataTables to see which one would suit you best.

You will need to add a reference to "Microsoft ActiveX Data Objects 2.7 Library" for the ADODB stuff to work.

Code:
Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ConnectDB As New ADODB.Connection
        Dim ConnectRS As New ADODB.Recordset
        Dim MyTable As String

        ConnectDB.Open("Provider=sqloledb;Data Source=hbcsql3;Initial Catalog=mailreader;User Id=***;Password=***;")

        MyTable = "select * from mail_info"
        ConnectRS.Open(MyTable, ConnectDB, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1)

        MsgBox(ConnectRS.RecordCount)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sqlConnection As New SqlConnection("Data Source=hbcsql3;Initial Catalog=mailreader;User Id=***;Password=***;")
        Dim sqlAdaptor As New SqlDataAdapter("SELECT * FROM mail_info", sqlConnection)
        Dim myTable As New DataTable

        sqlAdaptor.Fill(myTable)

        MsgBox(myTable.Rows.Count)
    End Sub
End Class
 
Wahey, it runs!

Form some reason the form is blank, and I can't get into edit it =/

All the code for objects is still there :S

Code:
    Private Sub InitializeComponent()
        Me.LContract = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TBRecords = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.TBName = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'LContract
        '
        Me.LContract.AutoSize = True
        Me.LContract.Location = New System.Drawing.Point(12, 9)
        Me.LContract.Name = "LContract"
        Me.LContract.Size = New System.Drawing.Size(39, 13)
        Me.LContract.TabIndex = 0
        Me.LContract.Text = "Label1"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(12, 22)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(67, 13)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Read by | on"
        '
        'TBRecords
        '
        Me.TBRecords.Location = New System.Drawing.Point(15, 38)
        Me.TBRecords.Name = "TBRecords"
        Me.TBRecords.Size = New System.Drawing.Size(265, 20)
        Me.TBRecords.TabIndex = 2
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(12, 163)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(200, 13)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "Please enter your name and tick the box."
        '
        'TBName
        '
        Me.TBName.Location = New System.Drawing.Point(15, 179)
        Me.TBName.Name = "TBName"
        Me.TBName.Size = New System.Drawing.Size(163, 20)
        Me.TBName.TabIndex = 4
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(205, 179)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 5
        Me.Button1.Text = "Submit"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'CheckBox1
        '
        Me.CheckBox1.AutoSize = True
        Me.CheckBox1.Location = New System.Drawing.Point(184, 182)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(15, 14)
        Me.CheckBox1.TabIndex = 6
        Me.CheckBox1.UseVisualStyleBackColor = True
        '
        'Post
        '
        Me.ClientSize = New System.Drawing.Size(292, 208)
        Me.Controls.Add(Me.CheckBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TBName)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.TBRecords)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.LContract)
        Me.Name = "Post"
        Me.Text = "Mail Acknowledgement"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

Any clues a side from rebuilding the entire form, it's not the first time it's done it either.
 
Do you get an error when you try to design the form?

Sometimes you can rebuild the project to fix errors with forms. On the menu choose "Build->Rebuild Solution"
 
Back
Top Bottom