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
        myConnection.Open()
        Dim insertCmd As New OleDb.OleDbCommand("Select * From Employee Where UserID= '" & UserName _
                            & "' AND Password = '" & Password & "'", myConnection)

        Try
            drUserID = insertCmd.ExecuteReader()

            While drUserID.Read
                MsgBox("Validated!", MsgBoxStyle.OkOnly, "Success")
                frmMain.Show()
                Me.Hide()

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

        Finally

        End Try

        myConnection.Close()
    End Sub




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

       myConnection.Open()

Here is the error message:

Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, 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.
LVL 2
gwosgoodIT MgrAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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.
0
All Courses

From novice to tech pro — start learning today.