Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2004, 08:16 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amjad1748
Default I have a problem plz help me

I have below code in asp.net using C# . but its giving me error as soon as i rn the programm.
The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\PCSWebApp3\PCSWebApp3.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
my code is below

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace PCSWebApp3
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.TextBox nameBox;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateName;
        protected System.Web.UI.WebControls.Calendar calendar;
        protected System.Web.UI.WebControls.TextBox eventBox;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateEvent;
        protected System.Web.UI.WebControls.DropDownList roomList;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateRoom;
        protected System.Web.UI.WebControls.ListBox attendeeList;
        protected System.Web.UI.WebControls.RequiredFieldValidator validateAttendees;
        protected System.Web.UI.WebControls.Button submitButton;
        protected System.Web.UI.WebControls.ValidationSummary validationSummary;
        protected System.Web.UI.WebControls.Label resultLabel;
        protected System.Data.DataSet ds;
        protected System.Data.DataTable eventTable;
        protected System.Data.OleDb.OleDbDataAdapter daAttendees;
        protected System.Data.OleDb.OleDbDataAdapter daRooms;
        protected System.Web.UI.WebControls.DataGrid eventDetails1;
        protected System.Web.UI.WebControls.DataList eventDetails2;
        protected System.Web.UI.WebControls.Label edName;
        protected System.Web.UI.WebControls.Label edDate;
        protected System.Web.UI.WebControls.Label edRoom;
        protected System.Web.UI.WebControls.Label edAttendees;
        protected System.Data.OleDb.OleDbDataAdapter daEvents;
        protected System.Data.OleDb.OleDbConnection oleDbConnection1;
        protected System.Data.OleDb.OleDbCommand oleDbCommand;


        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            oleDbConnection1.Open();
            ds = new DataSet();
            daAttendees = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Attendees", oleDbConnection1);
            daRooms = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Rooms", oleDbConnection1);
            daEvents = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Events", oleDbConnection1);

            daAttendees.Fill(ds, "Attendees");
            daRooms.Fill(ds, "Rooms");
            daEvents.Fill(ds, "Events");
            attendeeList.DataSource = ds.Tables["Attendees"];
            roomList.DataSource = ds.Tables["Rooms"];
            eventTable = ds.Tables["Events"];
            eventDetails1.DataSource = eventTable;
            eventDetails2.DataSource = eventTable;

            if (!this.IsPostBack)
            {
                System.DateTime trialDate = System.DateTime.Now;
                calendar.SelectedDate = getFreeDate(trialDate);
                this.DataBind();
            }
            else
            {
                eventDetails1.DataBind();
                eventDetails2.DataBind();
            }
            oleDbConnection1.Close();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
            this.calendar.SelectionChanged += new System.EventHandler(this.calendar_SelectionChanged );
            this.submitButton.Click += new System.EventHandler(this.submitButton_Click);
            this.eventDetails2.SelectedIndexChanged += new System.EventHandler(this.eventDetails2_SelectedInd exChanged);
            //
            // oleDbConnection1
            //
            this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";Us er ID=Admin;Data Source=C:\\Inetpub" +
                "\\wwwroot\\PCSWebApp3\\PCSWebApp3.mdb";
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void submitButton_Click(object sender, System.EventArgs e)
        {
            if (this.IsValid)
            {
                String attendees = "";
                foreach (ListItem attendee in attendeeList.Items)
                {
                    if (attendee.Selected)
                    {
                        attendees += attendee.Text + " (" + attendee.Value + "), ";
                    }
                }
                attendees += " and " + nameBox.Text;
                String dateString = calendar.SelectedDate.Date.Date.ToShortDateString( );
                String oleDbCommand = "INSERT INTO Events (Name, Room, " +
                                        "AttendeeList, EventDate) VALUES ('" +
                                        eventBox.Text + "', '" +
                                        roomList.SelectedItem.Value + "', '" +
                                        attendees + "', '" + dateString + "')";


                System.Data.OleDb.OleDbCommand insertCommand = new System.Data.OleDb.OleDbCommand(oleDbCommand, oleDbConnection1);

                oleDbConnection1.Open();
                int queryResult = insertCommand.ExecuteNonQuery();


                if (queryResult == 1)
                {
                    resultLabel.Text = "Event Added.";
                    daEvents = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM Events", oleDbConnection1);
                    ds.Clear();
                    daEvents.Fill(ds, "Events");
                    eventTable = ds.Tables["Events"];
                    calendar.SelectedDate = getFreeDate(calendar.SelectedDate.AddDays(1));
                    eventDetails1.DataBind();
                    eventDetails2.DataBind();
                }
                else
                {
                    resultLabel.Text = "Event not added due to DB access problem.";
                }
                oleDbConnection1.Close();
            }
        }

        private System.DateTime getFreeDate(System.DateTime trialDate)
        {
            if (eventTable.Rows.Count > 0)
            {
                System.DateTime testDate;
                bool trialDateOK = false;
                while (!trialDateOK)
                {
                    trialDateOK = true;
                    foreach (System.Data.DataRow testRow in eventTable.Rows)
                    {
                        testDate = (System.DateTime)testRow["EventDate"];
                        if (testDate.Date == trialDate.Date)
                        {
                            trialDateOK = false;
                            trialDate = trialDate.AddDays(1);
                        }
                    }
                }
            }
            return trialDate;
        }

        private void calendar_SelectionChanged(object sender, System.EventArgs e)
        {
            System.DateTime trialDate = calendar.SelectedDate;
            calendar.SelectedDate = getFreeDate(trialDate);
        }

        protected void calendar_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
        {
            if (eventTable.Rows.Count > 0)
            {
                System.DateTime testDate;
                foreach (System.Data.DataRow testRow in eventTable.Rows)
                {
                    testDate = (System.DateTime)testRow["EventDate"];
                    if (testDate.Date == e.Day.Date)
                    {
                        e.Cell.BackColor = Color.Red;
                    }
                }
            }
        }

        protected void eventDetails2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            eventDetails2.DataBind();
            DataRow selectedEventRow = eventTable.Rows[eventDetails2.SelectedIndex];
            edName.Text = (string)selectedEventRow["Name"];
            edDate.Text = "<b>Date:</b> " + ((DateTime)selectedEventRow["EventDate"]).ToLongDateString();
            edAttendees.Text = "<b>Attendees:</b> " + (string)selectedEventRow["AttendeeList"];
            DataRow selectedEventRoomRow = ds.Tables["Rooms"].Rows[(int)selectedEventRow["Room"] - 1];
            edRoom.Text = "<b>Room:</b> " + selectedEventRoomRow["Room"];
        oleDbConnection1.Close();
        }
    }
}


Plz help me i will be igly obliged him.


S.A.Ali
 
Old May 9th, 2004, 10:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear Ali:
I didnt check ur code but if u code is fine (if u use a book or any) ur problem should be on ur Forlder permission!
As u r using Access as ur DB, grant Write permission to that folder, BUt it seems u have make any sub-Folder! So first make a Sub-Folder for ur project & place ur .mdb file there & grant Write permission! It'll be ok!

Keep in toych in any problem.

Always:),
Hovik Melkomian.
 
Old May 9th, 2004, 12:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The error you get is caused by a permissions problem. The Web server is not allowed to write to the .MDB database file.

Check out this FAQ to find out how you can configure your system so your Web application is allowed to write tot the file:

http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=290

It's also a good idea to go with what Hovik said: Move your database to another folder, like C:\Databases, or at least to a /Databases folder in the root of your site. This makes it easier to find stuff and easier to configure the security for your site.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Where I End And You Begin by Radiohead (Track 6 from the album: Hail To The Thief) What's This?
 
Old May 10th, 2004, 07:09 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amjad1748
Default

Thanx imar & melvik and i m going through ur suggession let me overcome this problem and i'll let u know.

Best regards
S.A.Ali

S.A.Ali
 
Old August 18th, 2004, 09:45 PM
Authorized User
 
Join Date: Aug 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You problems is just the file permission only.

Change your .mdb files security to read write execute and it should work nicely.



~ Human Knowledge Belongs to the World !





Similar Threads
Thread Thread Starter Forum Replies Last Post
plz.....plz solve out my problem.... kethireddy435 ASP.NET 1.x and 2.0 Application Design 1 October 4th, 2007 12:56 PM
plz solve my problem mkazim85 SQL Language 2 May 14th, 2007 05:31 AM
Hi,plz solve my problem SachinMalge ASP.NET 1.0 and 1.1 Professional 1 December 26th, 2006 06:39 AM
Most Important Problem! Plz Help [email protected] ASP.NET 2.0 Professional 3 September 28th, 2006 01:43 AM
PrintReport() Problem ...Plz Help chansimone Crystal Reports 1 December 1st, 2004 04:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.