By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

ADO.NET problems to access data and saving date/time to database

P: n/a
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
write. 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.

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.
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ruy

What you mean with MS Access database is in the correct directory.

Are you sure that the ASPNET user has all rights to use it.

Mostly is that this problem.

I hope this helps

Cor
Nov 16 '05 #2

P: n/a
Hello,

thanks for answering, but I still couldn't access the file.

- MS Access is in a directory with permission to read and write (on IIS),
that's what a mean my "right" directory.

- 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?

Thanks a lot.

"Cor Ligthert" <no************@planet.nl> escreveu na mensagem
news:uD**************@TK2MSFTNGP09.phx.gbl...
Ruy

What you mean with MS Access database is in the correct directory.

Are you sure that the ASPNET user has all rights to use it.

Mostly is that this problem.

I hope this helps

Cor

Nov 16 '05 #3

P: n/a
Ruy,

My problem is that when I have solved this I forget it again.

However it is so often asked that in my opinion in the ASPNET newsgroup you
get direct all answers.

You can search it as well on the exact message when you get that is in
English, than you will find it for sure. (Probably you don't get this exact
message in English and than I know that searching for this is a hell).

Maybe you can ask it in the ASPNET newsgroup, because it is one of the most
asked problems in my opinion. (However see the rest of my message first
before you click :-) )

Aspnet
news://msnews.microsoft.com/microsof...amework.aspnet

Web interface:
http://communities2.microsoft.com/co...amework.aspnet

I see I missed your second question.

Better are the commandparameters to use. Than you can tell the format of the
datetime and use that directly by setting the value to the datetime you
want. Than you are direct rid from all culture or whatever problem like
that.

http://msdn.microsoft.com/library/de...eterstopic.asp

For that is as well a better newsgroup (not to send you away, just to make
you attent on that ).

Adonet
news://msnews.microsoft.com/microsof...amework.adonet

Web interface:
http://communities2.microsoft.com/co...amework.adonet

I hope this helps

Cor

Nov 16 '05 #4

P: n/a
Thanks, I'll try that.

"Cor Ligthert" <no************@planet.nl> escreveu na mensagem
news:%2****************@TK2MSFTNGP09.phx.gbl...
Ruy,

My problem is that when I have solved this I forget it again.

However it is so often asked that in my opinion in the ASPNET newsgroup
you get direct all answers.

You can search it as well on the exact message when you get that is in
English, than you will find it for sure. (Probably you don't get this
exact message in English and than I know that searching for this is a
hell).

Maybe you can ask it in the ASPNET newsgroup, because it is one of the
most asked problems in my opinion. (However see the rest of my message
first before you click :-) )

Aspnet
news://msnews.microsoft.com/microsof...amework.aspnet

Web interface:
http://communities2.microsoft.com/co...amework.aspnet

I see I missed your second question.

Better are the commandparameters to use. Than you can tell the format of
the datetime and use that directly by setting the value to the datetime
you want. Than you are direct rid from all culture or whatever problem
like that.

http://msdn.microsoft.com/library/de...eterstopic.asp

For that is as well a better newsgroup (not to send you away, just to make
you attent on that ).

Adonet
news://msnews.microsoft.com/microsof...amework.adonet

Web interface:
http://communities2.microsoft.com/co...amework.adonet

I hope this helps

Cor

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.