• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

error window when connecting to MS access database...

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
rabmissouri
Asked:
rabmissouri
  • 11
  • 11
  • 2
1 Solution
 
trevorhartmanCommented:
make sure you don't have your DB open in access

-Trevor
0
 
ayha1999Commented:
Hi,

Could u pls. post how you open the connection?

ayha
0
 
rabmissouriAuthor Commented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
trevorhartmanCommented:
Yes, Access locks everything while you have it open.  Close out of access, then try it
0
 
ayha1999Commented:
HI,

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

ayha
0
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:
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
 
ayha1999Commented:
sorry

iside your  Sub DataBind1()

ayha
0
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:

 <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
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:
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
 
rabmissouriAuthor Commented:
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
 
rabmissouriAuthor Commented:
Rather  the second error is 'connection' not declared

RABMissouri
0
 
ayha1999Commented:
Hi,

change this

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

to

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

ayha
0
 
rabmissouriAuthor Commented:
I am getting one last compiler error.

    If Con.state <> connection.Open Then

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

Thnaks,
RABMissouri
0
 
ayha1999Commented:
sorry a typo,

It should be like this;

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

ayha
0
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:
hi,

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

ayha
0
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:
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
 
rabmissouriAuthor Commented:
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
 
ayha1999Commented:
Hey,

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

ayha
0
 
rabmissouriAuthor Commented:
Ok, I am increasing the question by 50 points ....thanks for your help!

RABMissouri
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 11
  • 11
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now