Insert data into Access database

  • Thread starter Larry B via DotNetMonster.com
  • Start date
L

Larry B via DotNetMonster.com

Hello,

I seem to be having a problem with inserting data, from a web form, into an
access database. I have tried
to do the same thing in a regular windows app, there it works fine, but when
I try to do the same thing in an ASP. NET form I get an error saying the
'query needs to be updateable'. The code is identical, except for a little
difference in the connection string.

Here is my code in the web form, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;Data Source=" + this.Server.MapPath("JobRegistry.mdb") + ";");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999', '2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This generates the error message I receive:
'Operation must use an updateable query'



This is the same code used in the windows app, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;DataSource=JobRegistry.mdb");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999', '2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This works fine.

Seems I am missing missing something somewhere. This is basically my first
attempt at working with a database source using ASP.NET and a web form. Any
help would be appreciated!

Thank You
Larry Burnett
 
M

Marc

Have you tried pasting your query into a 'query' in access and running
it? Does it work ok?
 
G

Grant Merwitz

I've had that error before, can't remember exactly how i fixed it.


Just checked the permissions on the Access file, try setting the Security on
either the .mdb file, or the folder its in.
To test, set security to allow full control to everyone, and test it then
 
Y

Yves Peneveyre

Hello Larry !

It is working with your windows app, because the user which is running your application is _you_.
In a web application, your application is run by a process named aspnet_wp.exe. This process
runs using a specific account (normally ASPNET). So, to fix your problem, try to grant access in
write mode for the user ASPNET on your access file.

It should work.....

Best Regards

Yves Peneveyre
Hello,

I seem to be having a problem with inserting data, from a web form, into an
access database. I have tried
to do the same thing in a regular windows app, there it works fine, but when
I try to do the same thing in an ASP. NET form I get an error saying the
'query needs to be updateable'. The code is identical, except for a little
difference in the connection string.

Here is my code in the web form, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;Data Source=" + this.Server.MapPath("JobRegistry.mdb") + ";");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999', '2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This generates the error message I receive:
'Operation must use an updateable query'



This is the same code used in the windows app, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;DataSource=JobRegistry.mdb");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999', '2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This works fine.

Seems I am missing missing something somewhere. This is basically my first
attempt at working with a database source using ASP.NET and a web form. Any
help would be appreciated!

Thank You
Larry Burnett
 
P

Paul Clement

¤ Hello,
¤
¤ I seem to be having a problem with inserting data, from a web form, into an
¤ access database. I have tried
¤ to do the same thing in a regular windows app, there it works fine, but when
¤ I try to do the same thing in an ASP. NET form I get an error saying the
¤ 'query needs to be updateable'. The code is identical, except for a little
¤ difference in the connection string.
¤
¤ Here is my code in the web form, from a button click handler:
¤
¤ OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
¤ OLEDB.4.0;Data Source=" + this.Server.MapPath("JobRegistry.mdb") + ";");
¤ OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
¤ job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999', '2',
¤ 'OK', 'OKLOCATION')", DBConnection);
¤ cmd.Connection.Open();
¤ cmd.ExecuteNonQuery();
¤ cmd.Connection.Close();
¤
¤ This generates the error message I receive:
¤ 'Operation must use an updateable query'
¤

See the following:

http://support.microsoft.com/default.aspx?scid=kb;en-us;316675


Paul
~~~~
Microsoft MVP (Visual Basic)
 
A

ASP Newbie

Hi,

I had a similar problem. After reading your response I looked at the users
of my Windows XP. Indeed there was a user ASPNET_WP with limited rights.
After changing the account type to Computer administrator, everything worked
fine.

Thank for your help.

ASP newbie
"Yves Peneveyre" <Yves dot Peneveyre at ctp dot com> wrote in message
Hello Larry !

It is working with your windows app, because the user which is running your
application is _you_.
In a web application, your application is run by a process named
aspnet_wp.exe. This process
runs using a specific account (normally ASPNET). So, to fix your problem,
try to grant access in
write mode for the user ASPNET on your access file.

It should work.....

Best Regards

Yves Peneveyre
15:13:10 >>>
Hello,

I seem to be having a problem with inserting data, from a web form, into an
access database. I have tried
to do the same thing in a regular windows app, there it works fine, but when
I try to do the same thing in an ASP. NET form I get an error saying the
'query needs to be updateable'. The code is identical, except for a little
difference in the connection string.

Here is my code in the web form, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;Data Source=" + this.Server.MapPath("JobRegistry.mdb") + ";");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999',
'2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This generates the error message I receive:
'Operation must use an updateable query'



This is the same code used in the windows app, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;DataSource=JobRegistry.mdb");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999',
'2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This works fine.

Seems I am missing missing something somewhere. This is basically my first
attempt at working with a database source using ASP.NET and a web form. Any
help would be appreciated!

Thank You
Larry Burnett
 
Y

Yves Peneveyre

Hello !

I think it is not the best solution.
As I understand what you did, you added the ASPNET account into the Administrators group.
This is not very good, because all your web applications will run with privileged rights.
I suggested to add the write rights on the Access file for the ASPNET account.
But, anyway, if it is working......that's fine !


Yves Peneveyre
Hi,

I had a similar problem. After reading your response I looked at the users
of my Windows XP. Indeed there was a user ASPNET_WP with limited rights.
After changing the account type to Computer administrator, everything worked
fine.

Thank for your help.

ASP newbie
"Yves Peneveyre" <Yves dot Peneveyre at ctp dot com> wrote in message
Hello Larry !

It is working with your windows app, because the user which is running your
application is _you_.
In a web application, your application is run by a process named
aspnet_wp.exe. This process
runs using a specific account (normally ASPNET). So, to fix your problem,
try to grant access in
write mode for the user ASPNET on your access file.

It should work.....

Best Regards

Yves Peneveyre
15:13:10 >>>
Hello,

I seem to be having a problem with inserting data, from a web form, into an
access database. I have tried
to do the same thing in a regular windows app, there it works fine, but when
I try to do the same thing in an ASP. NET form I get an error saying the
'query needs to be updateable'. The code is identical, except for a little
difference in the connection string.

Here is my code in the web form, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;Data Source=" + this.Server.MapPath("JobRegistry.mdb") + ";");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999',
'2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This generates the error message I receive:
'Operation must use an updateable query'



This is the same code used in the windows app, from a button click handler:

OleDbConnection DBConnection = new OleDbConnection("Provider=Microsoft.JET.
OLEDB.4.0;DataSource=JobRegistry.mdb");
OleDbCommand cmd = new OleDbCommand("INSERT INTO Jobs (job_id, job_name,
job_num, div_id, builder, location) VALUES ('0000-000', 'test1', '3999',
'2',
'OK', 'OKLOCATION')", DBConnection);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();

This works fine.

Seems I am missing missing something somewhere. This is basically my first
attempt at working with a database source using ASP.NET and a web form. Any
help would be appreciated!

Thank You
Larry Burnett
 
L

Larry B via DotNetMonster.com

Thanks Paul,

I followed the link and one of the resolutions took care of the problem. I
did set the 'processModel' to 'SYSTEM' and that does seem to work good. I
appreciate the help from you and everyone that helped with this issue. I
have been struggling for days trying to figure it out. Finally over the hump
(whew)!

Thanks Again!
Larry Burnett
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top