OleDbException was unhandled error?

Brad

Member
Joined
Mar 26, 2007
Messages
12
Programming Experience
Beginner
Hi, I seem to be getting this error and I have no idea how to fix it, everything is correct with passwords etc (the *'s are for security only) here is the code for you guys to have a look at.

conn.Open() - is where the error is hapeening, this is my first time working with databases, so I am really pleased to come this far but I am baffled :p

Many Thanks!

VB.NET:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim anIntArray As Integer() = New Integer() {}
    Dim mypath = Application.StartupPath & "C:\Temp\myDB.accdb"
    Dim mypassword = "********"
    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mypath & ";Jet OLEDB:Database Password=" & mypassword)
    Dim cmd As OleDbCommand
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Computer.Network.IsAvailable() Then
            My.Computer.Network.DownloadFile("http://www.runeexile.info/123abcxxxxk5/myDB.accdb", "C:\Temp\myDB.accdb", "****", "******", True, 10000, True, FileIO.UICancelOption.DoNothing)
        Else
            MsgBox("An Internet connection could not be established, please check your network settings.")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sql = "SELECT UserID ,PassID FROM MYTAB WHERE USERID='" & TextBox1.Text & "' AND PASSID='" & TextBox2.Text & "'"

        cmd = New OleDbCommand(sql, conn)
        [B][SIZE="3"]conn.Open()[/SIZE][/B]
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        Try
            If dr.Read = False Then
                MessageBox.Show("Authentication failed...")
            Else
                MessageBox.Show("Login successfully...")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub
End Class
 
If you simply declare your connection and open it without any other code, does it give the same Exception? And what is the exception's type and message? I am thinking it's a problem with your connection string, but I must admit I have written that many of those manually...

What I would suggest is to create a new connection using visual studio's server explorer and retrieving the connection string from the Settings of your project. If you don't know how to do that, just ask :)
 
Back
Top