?
Solved

error window when connecting to MS access database...

Posted on 2005-04-08
24
Medium Priority
?
218 Views
Last Modified: 2010-04-07
Hello,

I set up a web form on asp.net to connect to an MS access data base using the instructions at the following website http://aspalliance.com/429  When I  build the project I get a browser window which gives me the following error message below.

Any help would be appreciated...Thanks....


Server Error in '/MyApplication1' Application.
--------------------------------------------------------------------------------

The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

Source Error:


Line 56:         Dim ds As New DataSet
Line 57:
Line 58:         adp.Fill(ds)
Line 59:
Line 60:         DataGrid1.DataSource = ds
 

Source File: c:\inetpub\wwwroot\MyApplication1\WebForm1.aspx.vb    Line: 58

Stack Trace:


[OleDbException (0x80004005): The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb'.  It is already opened exclusively by another user, or you need permission to view its data.]
   System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
   System.Data.OleDb.OleDbConnection.InitializeProvider()
   System.Data.OleDb.OleDbConnection.Open()
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
   System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   MyApplication1.WebForm1.DataBind1() in c:\inetpub\wwwroot\MyApplication1\WebForm1.aspx.vb:58
   MyApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\MyApplication1\WebForm1.aspx.vb:46
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

 

0
Comment
Question by:rabmissouri
  • 11
  • 11
  • 2
24 Comments
 
LVL 8

Expert Comment

by:trevorhartman
ID: 13737909
make sure you don't have your DB open in access

-Trevor
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13737961
Hi,

Could u pls. post how you open the connection?

ayha
0
 

Author Comment

by:rabmissouri
ID: 13739642
The data base was open in MS access when the asp.net error message occured.

I open the connection programatically in asp.net. (ie pressing <F5>)  I used the example code  posted at the following website http://aspalliance.com/429 

Is it possible that MS access has locked the record and won't let asp.net have use of it?

Thanks,
RABMissouri
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:trevorhartman
ID: 13740337
Yes, Access locks everything while you have it open.  Close out of access, then try it
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13742077
HI,

If you can post the connection code I will try to help you.

ayha
0
 

Author Comment

by:rabmissouri
ID: 13742342
Here is the code to this project.  Thanks for all your help!

RABMissouri

--------------------------------------------------------------------

Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Data Source=""C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb"";Mode=Shar" & _
        "e Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB" & _
        ":System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Prope" & _
        "rties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database" & _
        "=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Com" & _
        "pact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
        '
        'OleDbCommand1
        '
        Me.OleDbCommand1.CommandText = "Select * from xyzz;"
        Me.OleDbCommand1.Connection = Me.OleDbConnection1

    End Sub
    Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Protected WithEvents OleDbCommand1 As System.Data.OleDb.OleDbCommand
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            DataBind1()
        End If


    End Sub

    Sub DataBind1()

        Dim adp As New OleDb.OleDbDataAdapter(OleDbCommand1)

        Dim ds As New DataSet

        adp.Fill(ds)

        DataGrid1.DataSource = ds

        DataGrid1.DataBind()



    End Sub



End Class





<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="MyApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 128px"
                        runat="server" Width="136px" Height="64px"></asp:DataGrid>
            </form>
      </body>
</HTML>
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13743285
Hi,

try this instead of your connections and commands. put the modified code in the beginning of your sub.

     Dim Con As New OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb;Jet OLEDB:Database Password=;")
       
        Dim str as string= "Select * from xyzz;"
        Dim cmd As New OleDbCommand = new OleDbCommand(str,con)
        If con.state <>connection.Open then
              con.open
        End If


just remove the following from your page.

 Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Data Source=""C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb"";Mode=Shar" & _
        "e Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB" & _
        ":System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Prope" & _
        "rties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database" & _
        "=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Com" & _
        "pact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
        '
        'OleDbCommand1
        '
        Me.OleDbCommand1.CommandText = "Select * from xyzz;"
        Me.OleDbCommand1.Connection = Me.OleDbConnection1


ayha


0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13743286
sorry

iside your  Sub DataBind1()

ayha
0
 

Author Comment

by:rabmissouri
ID: 13743344
I am sorry...what code do you want me to delete and what code to add.

Can you put <delete> <delete> tags and <add> <add> tags please?

Thanks,
RABMissouri

0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13743541

 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
<delete>
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Data Source=""C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb"";Mode=Shar" & _
        "e Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB" & _
        ":System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Prope" & _
        "rties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database" & _
        "=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Com" & _
        "pact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
        '
        'OleDbCommand1
        '
        Me.OleDbCommand1.CommandText = "Select * from xyzz;"
        Me.OleDbCommand1.Connection = Me.OleDbConnection1
<delete>
    End Sub


 Sub DataBind1()

        Dim adp As New OleDb.OleDbDataAdapter(OleDbCommand1)

<add>

add modification here.

ayha
0
 

Author Comment

by:rabmissouri
ID: 13750475
I tried inserting the following code as you suggested:

 Dim Con As New OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb;Jet OLEDB:Database Password=;")
       
        Dim str as string= "Select * from xyzz;"
        Dim cmd As New OleDbCommand = new OleDbCommand(str,con)
        If con.state <>connection.Open then
              con.open
        End If
 
However, ASP did not recognize OleDbConnection or OleDbCommand

I wonder if the problem might be setting the proper permission in Access?

RABMissouri
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13751659
Hi,

---ASP did not recognize OleDbConnection or OleDbCommand

If you get compilation errors at OleDbConnection then at the top of the page do;

Imports System.Data.OleDb

what's error you are getting now. I think it is easy to spot?

ayha

0
 

Author Comment

by:rabmissouri
ID: 13753053
Dim cmd As New OleDbCommand = new OleDbCommand(str,con)    /*end of statement expected*/
        If Con.state <> connection.Open Then
            Con.open()       /*connection not defined*/
        End If


That helped a little.  I am still getting 2 compilation errors.  Please see above.

Thanks,
RABMissouri
0
 

Author Comment

by:rabmissouri
ID: 13753063
Rather  the second error is 'connection' not declared

RABMissouri
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13753315
Hi,

change this

 Dim cmd As New OleDbCommand = new OleDbCommand(str,con)

to

 Dim cmd As  OleDbCommand = new OleDbCommand(str,con)

ayha
0
 

Author Comment

by:rabmissouri
ID: 13753385
I am getting one last compiler error.

    If Con.state <> connection.Open Then

             /*name 'connection' is not declared.*/

Thnaks,
RABMissouri
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13753409
sorry a typo,

It should be like this;

 If Con.State <> ConnectionState.Open Then
            Con.Open()
        End If

ayha
0
 

Author Comment

by:rabmissouri
ID: 13753889
Thanks,

No more compile errors.

When I pressed <F5>  a browser  window opened with the following error message:

 The SelectCommand property has not been initialized before calling 'Fill'.


RABMissouri
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13754262
hi,

could u post you latest sub then I can fix that.

ayha
0
 

Author Comment

by:rabmissouri
ID: 13754672
Sub DataBind1()

        Dim adp As New OleDb.OleDbDataAdapter   (OleDbCommand1)
        Dim Con As New OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb;Jet OLEDB:Database Password=;")

        Dim str As String = "Select * from xyzz;"
        Dim cmd As OleDbCommand = New OleDbCommand(str, Con)
        If Con.State <> ConnectionState.Open Then
            Con.Open()
        End If



        Dim ds As New DataSet

        adp.Fill(ds)

        DataGrid1.DataSource = ds

        DataGrid1.DataBind()



    End Sub


Thanks,
RABMissouri
0
 
LVL 7

Accepted Solution

by:
ayha1999 earned 600 total points
ID: 13754731
Hi,

try this

Sub DataBind1()
        Dim adp As New OleDb.OleDbDataAdapter   (OleDbCommand1)
        Dim Con As New OleDbConnection( _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\Inetpub\wwwroot\MyApplication1\xyzz.mdb;Jet OLEDB:Database Password=;")

        Dim str As String = "Select * from xyzz;"
        Dim cmd As OleDbCommand = New OleDbCommand(str, Con)
        dim adp as OledbDataAdapter = New OleDbDataAdapter
       adp.SelectCommand=cmd
       Dim ds As DataSet= New DataSet

        If Con.State <> ConnectionState.Open Then
            Con.Open()
        End If
                   adp.Fill(ds)
        DataGrid1.DataSource = ds
        DataGrid1.DataBind()
    End Sub

ayha
0
 

Author Comment

by:rabmissouri
ID: 13758205
I am very impressed!!

I had to change:

dim adp as OledbDataAdapter = New OleDbDataAdapter

to:(due to compiler error)

adp  = New OleDbDataAdapter

and it works!!

For another 50 points can you tell me what the original problem was and what we did to fix it?  I know C++ but am new to asp.net

Thanks,
RABMissouri
0
 
LVL 7

Expert Comment

by:ayha1999
ID: 13764200
Hey,

You have allowed only 150 points for this question!? I thought a good points there. Try to increase the points pls.

ayha
0
 

Author Comment

by:rabmissouri
ID: 13765661
Ok, I am increasing the question by 50 points ....thanks for your help!

RABMissouri
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question