Request for OleDbPermission failed

Hello Coders.

Im trying to design a login form for a VB.Net 2005 project and im running into some problems along the way.  I am reading data from a locally-stored Access 2003 database.  Below is the sample code.

Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles cmdLogin.Click
        Dim UserName As String
        Dim Password As String
        UserName = txtUserName.Text
        Password = txtPassword.Text
        Dim myConnection As New OleDb.OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\dfranczyk\Desktop\PrecisionSecurity.mdb")
        Dim drUserID As OleDb.OleDbDataReader
        Dim insertCmd As New OleDb.OleDbCommand("Select * From Employee Where UserID= '" & UserName _
                            & "' AND Password = '" & Password & "'", myConnection)

            drUserID = insertCmd.ExecuteReader()

            While drUserID.Read
                MsgBox("Validated!", MsgBoxStyle.OkOnly, "Success")

            End While
        Catch ex As OleDb.OleDbException
            MsgBox("Test Failed", MsgBoxStyle.OkOnly)


        End Try

    End Sub

When I try to run the above code, I get an error on this statement:


Here is the error message:

Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Any idea of what I am doing wrong?  Any advice or suggestions would be greatly appreciated.  Thanks for your time.
gwosgoodIT MgrAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Joel CoehoornConnect With a Mentor Director of Information TechnologyCommented:
It's a 'trust' issue with the .Net framework.  This can happen for a number of reasons.  A few of the more common are not getting the correct trust level in your project settings, or running the program from a shared/network folder or drive.
All Courses

From novice to tech pro — start learning today.