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

I get this error:

I created a StartPage.aspx trying to link to the database with a hyperlink to another called index.aspx.  

I get this error when the page pops up, some data is display but no database(Access):
Could not find file 'c:\inetpub\wwwroot\BajaSalsa\BajaSalsa.mdb'.

My Hyperlink:

<asp:HyperLink id="HyperLink1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 32px" runat="server" Font-Size="XX-Large" BorderStyle="Double" BackColor="Yellow" BorderColor="Red" Font-Names="Trebuchet MS" ForeColor="Firebrick" NavigateUrl="index.aspx" Target="_new">Customers</asp:HyperLink>


The page I'm trying to hyperlink to:

Public Class index
    Inherits System.Web.UI.Page
    Protected WithEvents lblCart As System.Web.UI.WebControls.Label
    Private DTRProducts As System.Data.OleDb.OleDbDataReader
    Private DTRCategory As System.Data.OleDb.OleDbDataReader
    Private DB As New System.Data.OleDb.OleDbConnection
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents lblCartStatus As System.Web.UI.WebControls.Label
    Protected WithEvents DGrid As System.Web.UI.WebControls.DataGrid
    Protected WithEvents HyperLink2 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink3 As System.Web.UI.WebControls.HyperLink

    Protected WithEvents STRONG1 As System.Web.UI.HtmlControls.HtmlGenericControl
    Private Products As uc_shopping_cart
    Private UserCart As New CShoppingCart
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    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
        Try
            If IsPostBack Then
            Else
                UserCart = Session("UserCart")
                Me.lblCartStatus.Text = "Shopping Cart: " & UserCart.Display(Session("DBCon"))
                LoadData(Request.QueryString("category"))
            End If
        Catch ex As System.Exception

        End Try
    End Sub



    Private Sub LoadData(Optional ByVal Key As Long = 0)
        Try
            If Key = 0 Then Key = 1
            Dim DB As New System.Data.OleDb.OleDbConnection
            Dim DA As System.Data.OleDb.OleDbDataAdapter
            Dim DS As System.Data.DataSet
            DB = Session("DBCon")
            Dim SQL As String
            SQL = "Select * From qryProducts Where CategoryID=" & Key
            DA = New System.Data.OleDb.OleDbDataAdapter(SQL, DB)
            DS = New System.Data.DataSet
            DA.Fill(DS)
            DGrid.DataSource = DS
            DGrid.DataKeyField = "ProductID"
            DGrid.DataBind()
        Catch ex As System.Exception
            Response.Write(ex.Message)
        Finally

        End Try
    End Sub


    Private Sub DGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGrid.ItemCommand
        Try
            Dim itemCell As TableCell = e.Item.Cells(0)
            Dim item As String = itemCell.Text
            Dim txtQuantity As TextBox = e.Item.Cells(4).Controls(1)
            Dim Quantity As String = txtQuantity.Text
            If CType(e.CommandSource, LinkButton).CommandName = "AddToCart" Then
                UserCart = Session("UserCart")
                UserCart.Add(Quantity, item)
                Response.Write("<bgsound src='images/ching.wav' id='ching' loop='1'>")
                Me.lblCartStatus.Text = UserCart.Display(Session("DBCon"))
                Session("UserCart") = UserCart
            End If
        Catch ex As System.Exception
            Response.Write(ex.Message)
        End Try

    End Sub

    Private Sub DGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGrid.SelectedIndexChanged

    End Sub
End Class

0
daddyrat
Asked:
daddyrat
  • 4
  • 4
1 Solution
 
maidinhtaiCommented:
I'm not sure but you can change 'c:\inetpub\wwwroot\BajaSalsa\BajaSalsa.mdb' to 'file://c:/inetpub/wwwroot/BajaSalsa/BajaSalsa.mdb'.
0
 
daddyratAuthor Commented:
No it didn't work, came up browse can be found:  

file://c:/inetpub/wwwroot/BajaSalsa/BajaSalsa.mdb
0
 
arif_eqbalCommented:
Function LoadData....
DB = Session("DBCon")

Is the DB Connection always Open ?
How are you opening your Connection, Check where are you providing the Connection String
The Error is quite obvious its not able to find the Access Database file,
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!

 
daddyratAuthor Commented:
No that didn't either.  The database is being connected through Global.asax (only)

This is from uc_shopping_cart.ascx

Public MustInherit Class uc_shopping_cart
    Inherits System.Web.UI.UserControl
    Protected WithEvents Image1 As System.Web.UI.WebControls.Image
    Protected WithEvents cmdSaveCart As System.Web.UI.WebControls.Button
    Protected WithEvents cmdLoadCart As System.Web.UI.WebControls.Button
    Protected WithEvents cmdEmptyCart As System.Web.UI.WebControls.Button
    Protected WithEvents cmdCheckOut As System.Web.UI.WebControls.Button
    Protected WithEvents lblCartStatus As System.Web.UI.WebControls.Label
    Protected WithEvents DGrid As System.Web.UI.WebControls.DataGrid
    Protected WithEvents lblCartCount As System.Web.UI.WebControls.Label
    Protected WithEvents TD1 As System.Web.UI.HtmlControls.HtmlTableCell
    Private UserCart As New CShoppingCart
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    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 IsPostBack Then
            DisableButtons()
            Me.lblCartCount.Text = UserCart.Display(Session("DBCon"))
        Else
            DisableButtons()
            LoadData()
        End If
    End Sub
    Private Sub LoadData()
        Try
            UserCart = Session("UserCart")
            Me.lblCartCount.Text = UserCart.Display(Session("DBCon"))
            If UserCart.Count < 1 Then Me.lblCartStatus.Text = "Shopping Cart is Empty"
            DGrid.DataSource = UserCart.DSCart(Session("DBCon"))
            DGrid.DataBind()
        Catch ex As System.Exception


        End Try
    End Sub

    Private Sub DisableButtons()
        Try
            If InStr(Request.Url.ToString, "check_out") <> 0 Then
                Me.cmdCheckOut.Visible = False
                Me.cmdEmptyCart.Visible = False
                Me.cmdLoadCart.Visible = False
                Me.cmdSaveCart.Visible = False
            End If
        Catch ex As System.Exception

        End Try
    End Sub

    Private Sub cmdSaveCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveCart.Click
        Try
            If Session("Customer") = 0 Then
                Response.Redirect("signin.aspx?return=cart")
            Else
                UserCart = Session("UserCart")
                Me.lblCartStatus.Text = UserCart.Save(Session("Customer"), Session("DBCon"))
                Session("UserCart") = UserCart
            End If
        Catch ex As System.Exception

        End Try
    End Sub

    Private Sub cmdLoadCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadCart.Click
        Try
            If Session("Customer") = 0 Then
                Response.Redirect("signin.aspx?return=cart")
            Else
                UserCart = Session("UserCart")
                Me.lblCartStatus.Text = UserCart.Load(Session("Customer"), Session("DBCon"))
                Me.lblCartCount.Text = UserCart.Display(Session("DBCon"))
                Session("UserCart") = UserCart
                LoadData()
                Me.lblCartStatus.Text = ""
            End If
        Catch ex As System.Exception

        End Try
    End Sub

    Private Sub cmdEmptyCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEmptyCart.Click
        Try
            UserCart = Session("UserCart")
            UserCart.DeleteSavedCart(Session("Customer"), Session("DBCon"))
            UserCart.Clear()
            Me.lblCartCount.Text = UserCart.Display(Session("DBCon"))
            Session("UserCart") = UserCart
            LoadData()
            Me.lblCartStatus.Text = ""
        Catch ex As System.Exception

        End Try
    End Sub

    Private Sub DGrid_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DGrid.EditCommand
        Try
            Dim itemCell As TableCell = e.Item.Cells(0)
            Dim item As String = itemCell.Text
            Dim txtQuantity As TextBox = e.Item.Cells(1).Controls(1)
            Dim Quantity As String = txtQuantity.Text
            UserCart = Session("UserCart")
            UserCart.Edit(Quantity, item)
            Response.Write("<bgsound src='images/ching.wav' id='ching' loop='1'>")
            Me.lblCartCount.Text = UserCart.Display(Session("DBCon"))
            Session("UserCart") = UserCart
            LoadData()
        Catch ex As System.Exception


        End Try
    End Sub


    Private Sub cmdCheckOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCheckOut.Click
        Response.Redirect("check_out.aspx?return=check")
    End Sub

End Class
0
 
arif_eqbalCommented:
The problem lies in the code where you are opening the DB Connection
Check your Connection String, is it pointing to the MDB file properly ?
Use Relative Path and Server.MapPtah function, try to debug and see if the Path taken is right
0
 
daddyratAuthor Commented:
Thanks for the help, I have everything working the connection is fine.  My problem is I want to add a new web form and hyperlink or do I need the code somewhere to access index.aspx instead of hyperlink.  I’m new to this, so I’m really sure about the coding part.

Here is my connection code for the Global.asax:

Imports System.Web
Imports System.Web.SessionState

Public Class Global
    Inherits System.Web.HttpApplication

#Region " Component Designer Generated Code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

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

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        Dim UserCart As New CShoppingCart
        Try
            ' Fires when the session is started
            Session("DBCon") = DBCon()
            Session("UserCart") = UserCart
            Session("Customer") = 1
        Catch ex As System.Exception
        Finally

        End Try
    End Sub


    Function DBCon() As System.Data.OleDb.OleDbConnection
        Try
            Dim Path As String = Server.MapPath(".") & "\BajaSalsa.mdb"
            'Build Connection String
            Dim CString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
                Server.MapPath("BajaSalsa.mdb")
            'Open Database
            DBCon = New System.Data.OleDb.OleDbConnection(CString)
            DBCon.Open()
        Catch

        End Try
    End Function

    Function CloseDBCon(ByVal m_DBCon As System.Data.OleDb.OleDbConnection) As Boolean
        Try
            m_DBCon.Close()
        Catch

        End Try
    End Function

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires at the beginning of each request
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires upon attempting to authenticate the use
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        Session("UserCart") = Nothing
        CloseDBCon(Session("DBCon"))
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
    End Sub

End Class

0
 
arif_eqbalCommented:
So what I get from all this is that you have a Page called StratPage.aspx
You have placed a Hyperlink Control on this page which links to Index.aspx
This is fine, if you click on the link the page should open if it is in the same Root Folder (I think here BajaSalsa)
Now if you get an Error like MDB file not found it means the Page is trying to connect to the DB and is not able to find it, your code shows that you are looking for the Access Database File in the root folder "BajaSalsa"
So ensure that your MDB file is in the Folder BajaSalsa inside the wwwroot folder

As for the hyperlink control it should be fine in this case, when you use Hyperlink to navigate to a page the current page is not posted there, in case you want to retieve values of your TextBoxes or other controls on the page you are linking to then Use Server.Transfer("Index.aspx")

Also on a side note, storing an open connection object in Session variables is not a very good idea, imagine if you have 100 users connected you'd have 100 open connections to the DB throughout the session, the DB is bound to complain at some point. So try opening the connection only at the point it is required say on your index page
0
 
daddyratAuthor Commented:
I'm not an expert, but if I understand correctly - try to link to another location on the index page.  Is it possible to link to one of the HTML codes in the Index.aspx?  

Index.aspx (HTML)
%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb" Inherits="BajaSalsa.index" %>
>
<title>BajaSalsa Shopping Cart</title>

<asp:hyperlink id="HyperLink2" runat="server" NavigateUrl="index.aspx?category=1">Salsa Original Chunky</asp:hyperlink></P>
<asp:hyperlink id="HyperLink3" runat="server" NavigateUrl="index.aspx?category=2">Salsa Fire Roasted</asp:hyperlink></P>
                              
0
 
arif_eqbalCommented:
When you link to       index.aspx?category=1
all it will do is go to the Index.aspx page and pass it a QueryString called Category with value 1
So in your code say on Page_Load you should do whatever you want to do with this QueryString

In case you want that the hyperlink should directly take you to a section of your page, say for eg Index.aspx page is a very long page and you want that the Hyperlink should take you to the bottom of the page directly (this is waht I gather from  "try to link to another location on the index page") then that's fairly possible

put  <A HREF="#MyLocation"></a>   this code at the place in the page where you want to be then in the Hyperlink controls NavigateUrl property say this   "index.aspx#MyLocation"

Hope that's what you wanted


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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