Need help in VB.NET connecting to Access database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CM Manager via DotNetMonster.com

    #1

    Need help in VB.NET connecting to Access database

    I am very frustrated due to this exception error I am receiving. I've tried
    searching numerous user support groups, Microsoft Support Net, Google, etc.
    and haven't found exactly my situation. Hopefully someone here can help.

    I am just learning VB.NET and purchased the SAM's "Teach Yourself VB.NET
    2003 in 21 days' book. I am trying to connect to an Access database I created
    locally on my computer per Chapter 16. I originally had it on a network share
    but have also tried accessing it on my C:\ drive. I've created an
    OleDBConnection 1 along with the OleDbDataAdapte r1 and the DataSet11 per the
    book's instructions. I dragged a data grid onto a blank form and in the
    Properties window set its Datasource > DataSet11.Stude nts which is the name
    of my Access table (Students.mdb).

    I am receiving an error message stating "An unhandled exception of type
    'System.Securit y.SecurityExcep tion' occurred in DatabaseTests.e xe

    Additional information: Request failed" I've seen this probably has something
    to do with my permissions which I can adjust in the Microsoft .NET Framework
    Configuration utility, but I don't know what I'm looking for. Can someone
    please assist with troubleshooting this issue? Let me know if you need any
    additional information. Thank you!


    --
    Message posted via http://www.dotnetmonster.com
  • Terry

    #2
    Re: Need help in VB.NET connecting to Access database

    Does the asp worker process have rights to the directory where the mdb
    file is located?

    Comment

    • CM Manager via DotNetMonster.com

      #3
      Re: Need help in VB.NET connecting to Access database

      Terry wrote:[color=blue]
      >Does the asp worker process have rights to the directory where the mdb
      >file is located?[/color]

      I don't know because I don't know where the asp worker process rights are
      configured. What is the name of the config file where this is configured and
      where by default is it stored?


      --
      Message posted via http://www.dotnetmonster.com

      Comment

      • Rick Mogstad

        #4
        Re: Need help in VB.NET connecting to Access database

        Is this a web app or a windows app?


        "CM Manager via DotNetMonster.c om" <forum@DotNetMo nster.com> wrote in
        message news:530862F2A3 F36@DotNetMonst er.com...[color=blue]
        > Terry wrote:[color=green]
        >>Does the asp worker process have rights to the directory where the mdb
        >>file is located?[/color]
        >
        > I don't know because I don't know where the asp worker process rights are
        > configured. What is the name of the config file where this is configured
        > and
        > where by default is it stored?
        >
        >
        > --
        > Message posted via http://www.dotnetmonster.com[/color]


        Comment

        • CM Manager via DotNetMonster.com

          #5
          Re: Need help in VB.NET connecting to Access database

          Rick Mogstad wrote:[color=blue]
          >Is this a web app or a windows app?
          >[color=green][color=darkred]
          >>>Does the asp worker process have rights to the directory where the mdb
          >>>file is located?[/color][/color]
          >[quoted text clipped - 3 lines][color=green]
          >> and
          >> where by default is it stored?[/color][/color]

          It is a windows app. I've tried storing the VB code as well as the Access
          database *.mdb file both locally on my C:\ drive as well as on a network
          share drive. I get the same exception error message either way.


          --
          Message posted via http://www.dotnetmonster.com

          Comment

          • Terry

            #6
            Re: Need help in VB.NET connecting to Access database

            Does the mdb use security? If so try these as your connection string.

            Workgroup
            "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=\somepat h\mydb.mdb;Jet
            OLEDB:System Database=system .mdw;"

            Password
            "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=\somepat h\mydb.mdb;Jet
            OLEDB:Database Password=MyDbPa ssword;"

            If not try this:
            "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=\somepat h\mydb.mdb;User
            Id=admin;Passwo rd=;"

            Comment

            • landers

              #7
              Re: Need help in VB.NET connecting to Access database

              "CM Manager via DotNetMonster.c om" <forum@DotNetMo nster.com> wrote in
              message news:5308B40E2B 6C2@DotNetMonst er.com...[color=blue]
              > Rick Mogstad wrote:[color=green]
              >>Is this a web app or a windows app?
              >>[color=darkred]
              >>>>Does the asp worker process have rights to the directory where the mdb
              >>>>file is located?[/color]
              >>[quoted text clipped - 3 lines][color=darkred]
              >>> and
              >>> where by default is it stored?[/color][/color]
              >
              > It is a windows app. I've tried storing the VB code as well as the Access
              > database *.mdb file both locally on my C:\ drive as well as on a network
              > share drive. I get the same exception error message either way.
              >
              >
              > --
              > Message posted via http://www.dotnetmonster.com[/color]

              Hi,

              Please post your code.

              Have you tried opening the mdb file directly?

              Landers


              Comment

              • Tom C via DotNetMonster.com

                #8
                Re: Need help in VB.NET connecting to Access database

                landers wrote:[color=blue][color=green][color=darkred]
                >>>Is this a web app or a windows app?
                >>>[/color][/color]
                >[quoted text clipped - 7 lines][color=green]
                >> database *.mdb file both locally on my C:\ drive as well as on a network
                >> share drive. I get the same exception error message either way.[/color]
                >
                >Hi,
                >
                >Please post your code.
                >
                >Have you tried opening the mdb file directly?
                >
                >Landers[/color]

                Here is the code. It is very simple. A form with a data grid to load an
                Access table. One button to load the data grid and another to update the
                Access database. There is no security on the database as right now this is
                just a test to learn how to establish database connectivity and associating
                windows app controls with table fields via data binding.

                Public Class Form1
                Inherits System.Windows. Forms.Form

                #Region " Windows Form Designer generated code "

                Public Sub New()
                MyBase.New()

                'This call is required by the Windows Form Designer.
                InitializeCompo nent()

                'Add any initialization after the InitializeCompo nent() call

                End Sub

                'Form overrides dispose to clean up the component list.
                Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
                If disposing Then
                If Not (components Is Nothing) Then
                components.Disp ose()
                End If
                End If
                MyBase.Dispose( disposing)
                End Sub

                'Required by the Windows Form Designer
                Private components As System.Componen tModel.IContain er

                'NOTE: The following procedure is required by the Windows Form Designer
                'It can be modified using the Windows Form Designer.
                'Do not modify it using the code editor.
                Friend WithEvents OleDbSelectComm and1 As System.Data.Ole Db.OleDbCommand
                Friend WithEvents OleDbInsertComm and1 As System.Data.Ole Db.OleDbCommand
                Friend WithEvents OleDbConnection 1 As System.Data.Ole Db.OleDbConnect ion
                Friend WithEvents OleDbDataAdapte r1 As System.Data.Ole Db.OleDbDataAda pter
                Friend WithEvents DataGrid1 As System.Windows. Forms.DataGrid
                Friend WithEvents DataSet11 As TestDBApp.DataS et1
                Friend WithEvents Button1 As System.Windows. Forms.Button
                Friend WithEvents Button2 As System.Windows. Forms.Button
                <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
                InitializeCompo nent()
                Me.OleDbSelectC ommand1 = New System.Data.Ole Db.OleDbCommand
                Me.OleDbInsertC ommand1 = New System.Data.Ole Db.OleDbCommand
                Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
                Me.OleDbDataAda pter1 = New System.Data.Ole Db.OleDbDataAda pter
                Me.DataGrid1 = New System.Windows. Forms.DataGrid
                Me.DataSet11 = New TestDBApp.DataS et1
                Me.Button1 = New System.Windows. Forms.Button
                Me.Button2 = New System.Windows. Forms.Button
                CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).
                BeginInit()
                CType(Me.DataSe t11, System.Componen tModel.ISupport Initialize).
                BeginInit()
                Me.SuspendLayou t()
                '
                'OleDbSelectCom mand1
                '
                Me.OleDbSelectC ommand1.Command Text = "SELECT Grade, Name FROM
                Students"
                Me.OleDbSelectC ommand1.Connect ion = Me.OleDbConnect ion1
                '
                'OleDbInsertCom mand1
                '
                Me.OleDbInsertC ommand1.Command Text = "INSERT INTO Students(Grade,
                Name) VALUES (?, ?)"
                Me.OleDbInsertC ommand1.Connect ion = Me.OleDbConnect ion1
                Me.OleDbInsertC ommand1.Paramet ers.Add(New System.Data.Ole Db.
                OleDbParameter( "Grade", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Grade"))
                Me.OleDbInsertC ommand1.Paramet ers.Add(New System.Data.Ole Db.
                OleDbParameter( "Name", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Name"))
                '
                'OleDbConnectio n1
                '
                Me.OleDbConnect ion1.Connection String = "Jet OLEDB:Global Partial Bulk
                Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
                "ocking Mode=1;Data Source=""H:\Vis ual Basic .NET\Students.m db"";Jet
                OLEDB:Engine T" & _
                "ype=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:System
                database=;Jet OLEDB:SF" & _
                "P=False;persis t security info=False;Exte nded Properties=;Mod e=Share
                Deny None;Je" & _
                "t OLEDB:Encrypt Database=False; Jet OLEDB:Create System
                Database=False; Jet OLEDB:" & _
                "Don't Copy Locale on Compact=False;J et OLEDB:Compact Without Replica
                Repair=Fals" & _
                "e;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
                '
                'OleDbDataAdapt er1
                '
                Me.OleDbDataAda pter1.InsertCom mand = Me.OleDbInsertC ommand1
                Me.OleDbDataAda pter1.SelectCom mand = Me.OleDbSelectC ommand1
                Me.OleDbDataAda pter1.TableMapp ings.AddRange(N ew System.Data.Com mon.
                DataTableMappin g() {New System.Data.Com mon.DataTableMa pping("Table",
                "Students", New System.Data.Com mon.DataColumnM apping() {New System.Data.
                Common.DataColu mnMapping("Grad e", "Grade"), New System.Data.Com mon.
                DataColumnMappi ng("Name", "Name")})})
                '
                'DataGrid1
                '
                Me.DataGrid1.Da taMember = ""
                Me.DataGrid1.Da taSource = Me.DataSet11.St udents
                Me.DataGrid1.He aderForeColor = System.Drawing. SystemColors.
                ControlText
                Me.DataGrid1.Lo cation = New System.Drawing. Point(64, 48)
                Me.DataGrid1.Na me = "DataGrid1"
                Me.DataGrid1.Si ze = New System.Drawing. Size(272, 232)
                Me.DataGrid1.Ta bIndex = 0
                '
                'DataSet11
                '
                Me.DataSet11.Da taSetName = "DataSet1"
                Me.DataSet11.Lo cale = New System.Globaliz ation.CultureIn fo("en-US")
                '
                'Button1
                '
                Me.Button1.Loca tion = New System.Drawing. Point(72, 336)
                Me.Button1.Name = "Button1"
                Me.Button1.TabI ndex = 1
                Me.Button1.Text = "Load Data"
                '
                'Button2
                '
                Me.Button2.Loca tion = New System.Drawing. Point(256, 336)
                Me.Button2.Name = "Button2"
                Me.Button2.TabI ndex = 2
                Me.Button2.Text = "Save Data"
                '
                'Form1
                '
                Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
                Me.ClientSize = New System.Drawing. Size(408, 406)
                Me.Controls.Add (Me.Button2)
                Me.Controls.Add (Me.Button1)
                Me.Controls.Add (Me.DataGrid1)
                Me.Name = "Form1"
                Me.Text = "Form1"
                CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).End Init
                ()
                CType(Me.DataSe t11, System.Componen tModel.ISupport Initialize).End Init
                ()
                Me.ResumeLayout (False)

                End Sub

                #End Region

                Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
                System.EventArg s) Handles Button1.Click
                DataSet11.Clear ()
                OleDbDataAdapte r1.Fill(DataSet 11)
                End Sub

                Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
                System.EventArg s) Handles Button2.Click
                OleDbDataAdapte r1.Update(DataS et11)
                End Sub
                End Class


                --
                Message posted via http://www.dotnetmonster.com

                Comment

                • Terry

                  #9
                  Re: Need help in VB.NET connecting to Access database

                  Are you using Visual Studio .net to create the application? If so can
                  you connect to the MDB via the server explorer?

                  Add a new DB connecion. Then click to the provider tab change the
                  provier to MS Jet 4.0 OLE DB PRovider, then back to the Connection tab.
                  Pick your DB and test it.

                  Comment

                  • Maxicole Lucity

                    #10
                    Re: Need help in VB.NET connecting to Access database


                    I think you've changed the location of your file so many times now you
                    forgot to change the path.Maybe you forgot to change the permission
                    state and, create a new permission for yourself where the folder was
                    originally
                    alocated.rememb er this database is shared and you have just copied the
                    database without changing permission status.


                    *** Sent via Developersdex http://www.developersdex.com ***

                    Comment

                    • Solution

                      #11
                      Re: Need help in VB.NET connecting to Access database


                      No!.Bra try not to use the full path when assigning the data source,
                      reason being what if you move the file?.It will give you errors.Try to
                      copy the file into the same subdirectory as your solution, so that you
                      can only use ..\..\student.m db when referencing it in your code.



                      DFace

                      *** Sent via Developersdex http://www.developersdex.com ***

                      Comment

                      • Tom C via DotNetMonster.com

                        #12
                        Re: Need help in VB.NET connecting to Access database

                        Terry wrote:[color=blue]
                        >Are you using Visual Studio .net to create the application? If so can
                        >you connect to the MDB via the server explorer?
                        >
                        >Add a new DB connecion. Then click to the provider tab change the
                        >provier to MS Jet 4.0 OLE DB PRovider, then back to the Connection tab.
                        >Pick your DB and test it.[/color]

                        I've tried also using the Data Form Wizard to create my form. I'm able to
                        create the data connection using Server Explorer no problem. I used MS Jet 4.
                        0 OLE DB Provider and tested the connection with no problem. I've just put a
                        data grid on the form with two buttons called Load Data and Save Data.

                        The "Load Data" button has the following code:
                        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.
                        EventArgs) Handles Button1.Click
                        DataSet11.Clear ()
                        OleDbDataAdapte r1.Fill(DataSet 11)
                        End Sub

                        The "Save Data" button has the following code:
                        Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.
                        EventArgs) Handles Button2.Click
                        OleDbDataAdapte r1.Update(DataS et11)
                        End Sub

                        Everything else are defaults and I'm still getting the stupid Exception error
                        message. Is there something possibly that wasn't installed when I installed
                        VB.NET 2003, perhaps as part of a Custom installation that may be missing? I
                        would think it would be simple to load an Access database, but am having no
                        luck.


                        --
                        Message posted via DotNetMonster.c om
                        Best online pokies for real money in Australia and learn about safety and game mechanics in this comprehensive guide.

                        Comment

                        Working...