Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MS Access Database Connection with VB.NET

MS Access Database Connection with VB.NET

Scheduled Pinned Locked Moved Database
helpcsharpdatabasesecurity
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EdZa
    wrote on last edited by
    #1

    I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!

    L M 2 Replies Last reply
    0
    • E EdZa

      I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Edza, not sure, as I'd do it differently in C# ( using: OleDbConnection = new OleDBConnection(StrConnectionString) isntead, but have you tried leaving out the "..\", so you get: strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='..\PIB Hiring System.mdb'" Alternatively, drop the "\", and put the MDB in the RELEASE or DEBUG folder (depending obviously on which you are using). strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='PIB Hiring System.mdb'" regards, Pauwl Pauwl

      1 Reply Last reply
      0
      • E EdZa

        I am trying to connect my vb.net program to MS Access but nothing seems to be going ok. Whenever I declare my connection object, I get this kind of an error An unhandled exception of type 'System.Security.SecurityException' occurred in system.windows.forms.dll here is the code : This is at the very top ------------------------- Imports System Imports System.Data Imports System.Data.OleDb -------------------------- Dim cnn As OleDbConnection = New OleDbConnection() Dim strConnectionString As String Dim strApp_Path As String strApp_Path = System.IO.Directory.GetCurrentDirectory() strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strApp_Path & "\PIB Hiring System.mdb" cnn.ConnectionString = strConnectionString cnn.Open() my database is currently lying in the bin folder. The problem is it does not seem to like it when I declare my connection. Do I have to add anything to my project. Someone please help me!!!

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        I don't think it is related to the database. You're getting a SecurityException. You're probably trying to run this code from the network. Currently, the database access code requires Full Trust before it will run, which will only occur if running from the local machine. Copy your project to a local hard disk and try again.

        U 1 Reply Last reply
        0
        • M Mike Dimmick

          I don't think it is related to the database. You're getting a SecurityException. You're probably trying to run this code from the network. Currently, the database access code requires Full Trust before it will run, which will only occur if running from the local machine. Copy your project to a local hard disk and try again.

          U Offline
          U Offline
          User 591980
          wrote on last edited by
          #4

          What you are saying is 100 percent correct, because whenever I open my VB.NET framewok it gives me this kind of an error: "The project location is not fully trusted by the VB.NET runtime. This is either it is a network share or mapped to a network share not on the local machine. If the output path is under the project location your code will not execute as fully trusted and you may receive unexpected security exceptions. Click Ok to ignore and continue. Click cancel to choose a different project location." It runs like a dream from my local disk, just as you said. Thank you Mike, I never thought this error was the cause of all my nightmares. Thank you again mike, you saved 90% of my time.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups