Problems to access data and saving date/time to database

Discussion in 'ASP .Net' started by Ruy Castelli, Mar 4, 2005.

  1. Ruy Castelli

    Ruy Castelli Guest

    I created a ASP.NET page using C# and I'm using two components to access a
    MS-Access database, which are:

    - oleDbConnection
    - oleDataAdapter

    The MS-Access database is in the correct directory (IIS has permission to
    read/write) and everything seems ok, but IIS says that it can't open the
    file because there is someone else using it exclusively (impossible, I'm
    using a stand alone computer and I closed everything) or I need permission
    to open the file, which is strange too.

    On the .net framework configuration, I set all codes in my computer to have
    "full trust", is this the correct way of doing it? Or a should actually
    register the dll file on it? How is this supposed to be done?

    I also would like to know if the way I'm trying to save date/time to the
    database is correct.

    --------- code ---------

    protected System.Web.UI.WebControls.Label Label1;

    protected System.Web.UI.WebControls.RequiredFieldValidator
    RequiredFieldValidator1;

    protected System.Web.UI.WebControls.TextBox nome;

    protected System.Web.UI.WebControls.RequiredFieldValidator
    RequiredFieldValidator2;

    protected System.Web.UI.WebControls.TextBox msg;

    protected System.Web.UI.WebControls.Label Label2;

    protected System.Data.OleDb.OleDbConnection oleDbConnection1;

    protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

    protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

    protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

    protected System.Web.UI.WebControls.Label Erro;

    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    if (IsPostBack)
    {
    try {
    oleDbConnection1.Open();

    oleDbDataAdapter1.InsertCommand.CommandText =
    "INSERT INTO [msg log] "+
    "(hora, msg, nome) "+
    "VALUES ("+
    "'"+DateTime.Now.ToString()+"', "+
    "'"+nome.Text+"', "+
    "'"+msg.Text+"')";

    oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();

    oleDbConnection1.Close();

    nome.Text = "";
    msg.Text = "";

    Erro.Visible = false;
    }
    catch (System.Data.OleDb.OleDbException exception)
    {
    Erro.Visible = true;
    Erro.Text = "Erro no servidor: " +
    exception.ToString();
    }
    }
    }

    --------- code ---------

    Thanks.
     
    Ruy Castelli, Mar 4, 2005
    #1
    1. Advertising

  2. Hi Ruy Castelli,

    The problem arises , since the user you are using for running your
    application don't have permission to open the access file.


    Goto the folder location which contains the Access File.

    Select the propertis for that folder and goto the security tab. Make sure
    that ASPNET user is added in the list and has full permisson. Moreover if you
    are using a widnows based authentication ...then include that user account
    also in the list with necessary permission.

    Just make sure the same security settings for the mdb file too.

    Cheers,

    Jerome. M

    "Ruy Castelli" wrote:

    > I created a ASP.NET page using C# and I'm using two components to access a
    > MS-Access database, which are:
    >
    > - oleDbConnection
    > - oleDataAdapter
    >
    > The MS-Access database is in the correct directory (IIS has permission to
    > read/write) and everything seems ok, but IIS says that it can't open the
    > file because there is someone else using it exclusively (impossible, I'm
    > using a stand alone computer and I closed everything) or I need permission
    > to open the file, which is strange too.
    >
    > On the .net framework configuration, I set all codes in my computer to have
    > "full trust", is this the correct way of doing it? Or a should actually
    > register the dll file on it? How is this supposed to be done?
    >
    > I also would like to know if the way I'm trying to save date/time to the
    > database is correct.
    >
    > --------- code ---------
    >
    > protected System.Web.UI.WebControls.Label Label1;
    >
    > protected System.Web.UI.WebControls.RequiredFieldValidator
    > RequiredFieldValidator1;
    >
    > protected System.Web.UI.WebControls.TextBox nome;
    >
    > protected System.Web.UI.WebControls.RequiredFieldValidator
    > RequiredFieldValidator2;
    >
    > protected System.Web.UI.WebControls.TextBox msg;
    >
    > protected System.Web.UI.WebControls.Label Label2;
    >
    > protected System.Data.OleDb.OleDbConnection oleDbConnection1;
    >
    > protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
    >
    > protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
    >
    > protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
    >
    > protected System.Web.UI.WebControls.Label Erro;
    >
    > protected System.Web.UI.WebControls.Button Button1;
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > if (IsPostBack)
    > {
    > try {
    > oleDbConnection1.Open();
    >
    > oleDbDataAdapter1.InsertCommand.CommandText =
    > "INSERT INTO [msg log] "+
    > "(hora, msg, nome) "+
    > "VALUES ("+
    > "'"+DateTime.Now.ToString()+"', "+
    > "'"+nome.Text+"', "+
    > "'"+msg.Text+"')";
    >
    > oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
    >
    > oleDbConnection1.Close();
    >
    > nome.Text = "";
    > msg.Text = "";
    >
    > Erro.Visible = false;
    > }
    > catch (System.Data.OleDb.OleDbException exception)
    > {
    > Erro.Visible = true;
    > Erro.Text = "Erro no servidor: " +
    > exception.ToString();
    > }
    > }
    > }
    >
    > --------- code ---------
    >
    > Thanks.
    >
    >
    >
     
    =?Utf-8?B?RG90TmV0SmVyb21l?=, Mar 4, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,361
    Michael Borgwardt
    May 30, 2004
  2. Noozer
    Replies:
    2
    Views:
    1,168
    Noozer
    Aug 1, 2005
  3. Keith Cochrane
    Replies:
    2
    Views:
    649
    Keith Cochrane
    Aug 6, 2006
  4. jack
    Replies:
    2
    Views:
    590
  5. Rohit
    Replies:
    9
    Views:
    193
    Dr J R Stockton
    Jul 9, 2008
Loading...

Share This Page