By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

Need help in VB.NET connecting to Access database

P: n/a
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
OleDBConnection1 along with the OleDbDataAdapter1 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.Students which is the name
of my Access table (Students.mdb).

I am receiving an error message stating "An unhandled exception of type
'System.Security.SecurityException' occurred in DatabaseTests.exe

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
Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Does the asp worker process have rights to the directory where the mdb
file is located?

Nov 21 '05 #2

P: n/a
Terry wrote:
Does the asp worker process have rights to the directory where the mdb
file is located?


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
Nov 21 '05 #3

P: n/a
Is this a web app or a windows app?
"CM Manager via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:53***********@DotNetMonster.com...
Terry wrote:
Does the asp worker process have rights to the directory where the mdb
file is located?


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

Nov 21 '05 #4

P: n/a
Rick Mogstad wrote:
Is this a web app or a windows app?
Does the asp worker process have rights to the directory where the mdb
file is located?

[quoted text clipped - 3 lines]
and
where by default is it stored?


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
Nov 21 '05 #5

P: n/a
Does the mdb use security? If so try these as your connection string.

Workgroup
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet
OLEDB:System Database=system.mdw;"

Password
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet
OLEDB:Database Password=MyDbPassword;"

If not try this:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=;"

Nov 21 '05 #6

P: n/a
"CM Manager via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:53***********@DotNetMonster.com...
Rick Mogstad wrote:
Is this a web app or a windows app?
Does the asp worker process have rights to the directory where the mdb
file is located?

[quoted text clipped - 3 lines]
and
where by default is it stored?


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


Hi,

Please post your code.

Have you tried opening the mdb file directly?

Landers
Nov 21 '05 #7

P: n/a
landers wrote:
Is this a web app or a windows app?

[quoted text clipped - 7 lines]
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.


Hi,

Please post your code.

Have you tried opening the mdb file directly?

Landers


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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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 OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents DataSet11 As TestDBApp.DataSet1
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DataSet11 = New TestDBApp.DataSet1
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).
BeginInit()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).
BeginInit()
Me.SuspendLayout()
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT Grade, Name FROM
Students"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO Students(Grade,
Name) VALUES (?, ?)"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.
OleDbParameter("Grade", System.Data.OleDb.OleDbType.VarWChar, 50, "Grade"))
Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.
OleDbParameter("Name", System.Data.OleDb.OleDbType.VarWChar, 50, "Name"))
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""H:\Visual Basic .NET\Students.mdb"";Jet
OLEDB:Engine T" & _
"ype=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Je t OLEDB:System
database=;Jet OLEDB:SF" & _
"P=False;persist security info=False;Extended Properties=;Mode=Share
Deny None;Je" & _
"t OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet OLEDB:" & _
"Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=Fals" & _
"e;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.
DataTableMapping() {New System.Data.Common.DataTableMapping("Table",
"Students", New System.Data.Common.DataColumnMapping() {New System.Data.
Common.DataColumnMapping("Grade", "Grade"), New System.Data.Common.
DataColumnMapping("Name", "Name")})})
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataSet11.Students
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.
ControlText
Me.DataGrid1.Location = New System.Drawing.Point(64, 48)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(272, 232)
Me.DataGrid1.TabIndex = 0
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 336)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Load Data"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(256, 336)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Save Data"
'
'Form1
'
Me.AutoScaleBaseSize = 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.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit
()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit
()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet11)
End Sub
End Class
--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #8

P: n/a
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.

Nov 21 '05 #9

P: n/a

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.remember this database is shared and you have just copied the
database without changing permission status.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #10

P: n/a

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.mdb when referencing it in your code.

DFace

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #11

P: n/a
Terry wrote:
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.


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(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles Button1.Click
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
End Sub

The "Save Data" button has the following code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet11)
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.com
http://www.dotnetmonster.com/Uwe/For...b-net/200508/1
Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.