Link to home
Start Free TrialLog in
Avatar of gwosgood
gwosgoodFlag for United States of America

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial