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

asp.net insert command access database

help me pleasei Have one ASP.NET (access data mdb)  INSERT problem.
its working on my local computer but when i have uploaded it on my webserver
my connection sting isnt working

MY CONNECTION STRING IS AS FOLLOWS
=================================
        OleDbConnection dbcon2= new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection string"].ConnectionString);
        LblEmail.Text = TxtEmail.Text + ", Thankyou for Joining.";
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = dbcon2;
        cmd.CommandText = " insert into mailid(emails) values(@email)";
        cmd.Parameters.Add("@email", OleDbType.VarChar, 50).Value = Txt2mail.Text.Trim();
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();
        Response.Redirect("default.aspx");


ERROR ENCOUNTERED IS AS FOLLOWS
================================

Server Error in '/' Application.
--------------------------------------------------------------------------------

Operation must use an updateable query.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[OleDbException (0x80004005): Operation must use an updateable query.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +267
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +192
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +48
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +106
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +108
   Join.BtnSubmit_Click(Object sender, EventArgs e) +247
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

 
please help me what to do in this case
0
dontnetsanjay
Asked:
dontnetsanjay
1 Solution
 
Jai STech ArchCommented:
can you check in your webconfig file whether the ACCESS database is in the specified locatiuon;....

one option would be to create a ODBC connection for your access database and then use that DSN name to connect to the database rather than sopecifying the DB name explicityly...thts a best practise
0
 
Pratima PharandeCommented:
Have you changed the connection string properly in web.config file ?

s this is problem for all pages where using the connection string?
0
 
crisco96Commented:
Change your code to the following:

        OleDbConnection dbcon2= new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection string"].ConnectionString);
        LblEmail.Text = TxtEmail.Text + ", Thankyou for Joining.";
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = dbcon2;
        cmd.CommandText = " insert into mailid(emails) values(?)";
        cmd.Parameters.Add("@email", OleDbType.VarChar, 50);
        cmd.Parameters["@email"].Value = Txt2mail.Text.Trim();
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();
        Response.Redirect("default.aspx");

I think with oledb commands you have to specify parameters in the command text with ?'s, then the order you add them to the parameter collection is the order they are used in the command, the names really don't matter.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
dontnetsanjayAuthor Commented:
I will check this question mark,

I will recheck path and file name
otherwise it is working perfectly on my local webserver
0
 
muthan_vinothCommented:
The problem is you access database does not have enough rights. give enough permissions for IUSR and ASP.net in security tab at property sheet of both mdb and folder that contains mdb
0
 
dontnetsanjayAuthor Commented:
hello Muthan,

i have only a small space with this server
so i do not have any proviledge to asign permission on webserver

there fore i will request them to do so

even though i have mentioned my problem to them but not yet received any support

thanks
0
 
muthan_vinothCommented:
Hi Sanjay

There are no problems with your connection strings.

Please have a look  for more information
-http://forums.asp.net/p/154273/1944044.aspx

If your server is an UNIX one then use FTP Client such as FileZilla and Change file and directory mode to 777.

0
 
dontnetsanjayAuthor Commented:
i get u muthan
my sever (what i am told and i have paid is win server)
and it shows filemmodes  that is attrubutes -rw-rw-rw-
now what attributes should i use here

?
0
 
dontnetsanjayAuthor Commented:
yes mdb file attibutre is -rw-rw-rw-
and daabase attribute drw-rw-rw-
this for all other folders too
0
 
dontnetsanjayAuthor Commented:
Even Question mark does makeany change

hey I am using this statement in web.comfig file is it wrong?

        -->
            <authentication mode="Windows"/>
            <!--
0
 
muthan_vinothCommented:
1.       if you have FTP access , Open your FTP Using IExplore
2.      Expand the folder tree to the location of your Web site database file.
3.      Right-click Your_Web_Site_Database_Name.mdb, and then click Properties.
4.      Click the Security tab, and then click Add.
5.      In the Enter the object names to select box, type IIS_WPG, and then click OK.
6.      In the Group or user names list, click IIS_WPG.
7.      In the Permissions for IIS_WPG list, click to select the Allow check box that is next to Write.
8.      Click Add.
9.      In the Enter the object names to select box, type Network Service, and then click OK.
10.      In the Group or user names list, click Network Service.
11.      In the Permissions for Network Service list, click to select the Allow check box that is next to Write.
12.      Click Apply, and then click OK.

These steps apply for
machine\ASPNET, IIS_GPM, IUSR_machine, IWAM_machine, and everything else is IIS_GPM group
0
 
dontnetsanjayAuthor Commented:
how do we open ftp using explorer?
i am using FTP commander
i have tried using ftp://www,site name login box appears but it does not allow login even though I am entering right username and password it says could not login with username and pASSWORD SUPPPLIED
0
 
dontnetsanjayAuthor Commented:
hey okay but when i click onproperties it says it does not suport changing file permission
0
 
dontnetsanjayAuthor Commented:
Hello muthan,
Yes problem was with file access,

persmissin has been provided by my web host for the same.
icould not have done this at my end
thanks anywa ur answer made me argue with them for file access permission earlier they also said that check your connection string but yeah u were right again there was no problem with connection string

can u please also direct some link were ican get these kinda information whcih one needs to knw while hosting asp.net site

thanks oncce again
0
 
muthan_vinothCommented:
www.google.com this is not a joke.. reach me muthan_vinoth@yahoo.co.in
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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