|
Subject:
|
Chapter 9 - Update database Problem
|
|
Posted By:
|
chafor
|
Post Date:
|
12/29/2005 3:29:50 PM
|
First, I got a problem with this line: objContenuRequete.Update(objDataSetUtilisateur, "tblUtilisateur");
I try the solution given there : "http://p2p.wrox.com/topic.asp?TOPIC_ID=31885"
But it didn't work
Second, I was wondering if I can set the update query myself... Would it be alright to do something like dataAdapter = new OleDbDataAdapter("Update ... Where ...", dbConnection);?
objDataTable.Rows[0]["UTIL_MOTDEPASSE"] = strNouvHashMotDePasse; OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(objContenuRequete); objContenuRequete.UpdateCommand = commandBuilder.GetUpdateCommand(); objContenuRequete.Update(objDataSetUtilisateur, "tblUtilisateur");
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:
Line 160: OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(objContenuRequete); Line 161: objContenuRequete.UpdateCommand = commandBuilder.GetUpdateCommand(); Line 162: objContenuRequete.Update(objDataSetUtilisateur, "tblUtilisateur"); Line 163: return true; Line 164: }
Source File: C:\Inetpub\wwwroot\intra_ulysse\Charles\test6\ClasseUsager.cs Line: 162
Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.] System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +1662 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +152 ASP.Usager.ChangerMotDePasse(String strAncHashMotDePasse, String strNouvHashMotDePasse, String strConfHashMotDePasse) in C:\Inetpub\wwwroot\intra_ulysse\Charles\test6\ClasseUsager.cs:162 ASP.ChangeMotDePasse_aspx.Page_Load() in C:\Inetpub\wwwroot\intra_ulysse\Charles\test6\ChangeMotDePasse.aspx:30 System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +750
|
|
Reply By:
|
chafor
|
Reply Date:
|
12/30/2005 2:29:17 PM
|
I try something new...
objConnectionAccess = new OleDbConnection(strConnecAccess); objConnectionAccess.Open(); strSQL = "UPDATE tblUtilisateur SET UTIL_MOTDEPASSE='" + strNouvHashMotDePasse + "' WHERE UTIL_NOMDUTILISATEUR='" + _strNomDUtilisateur + "' AND UTIL_MOTDEPASSE='" + strAncHashMotDePasse + "'"; OleDbCommand myCommand = new OleDbCommand(strSQL,objConnectionAccess); myCommand.ExecuteNonQuery(); objConnectionAccess.Close(); return strSQL;
But it's still give me an error... I Know my sqlQuery is good because I try it directly in access....
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:
Line 155: Line 156: OleDbCommand myCommand = new OleDbCommand(strSQL,objConnectionAccess); Line 157: myCommand.ExecuteNonQuery(); Line 158: Line 159: objConnectionAccess.Close();
Source File: C:\Inetpub\wwwroot\intra_ulysse\charles\test6\ClasseUsager.cs Line: 157
Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66 ASP.Usager.ChangerMotDePasse(String strAncHashMotDePasse, String strNouvHashMotDePasse, String strConfHashMotDePasse) in C:\Inetpub\wwwroot\intra_ulysse\charles\test6\ClasseUsager.cs:157 ASP.ChangeMotDePasse_aspx.Page_Load() in C:\Inetpub\wwwroot\intra_ulysse\charles\test6\ChangeMotDePasse.aspx:45 System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +750
There's a weard thing appening when I try to open my db after I run the script... It seem the database open in read only mode...
Any Idea?
|
|
Reply By:
|
Imar
|
Reply Date:
|
12/30/2005 2:39:56 PM
|
Hi chafor,
80004005 error are almost always related to permission problems. Check out this FAQ to learn how to fix the situation:
http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=263
You may need this FAQ to determine the account used by your webserver:
http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=287
HtH and happy New Year,
Imar --------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
chafor
|
Reply Date:
|
12/30/2005 3:08:51 PM
|
I'hav already try this... if I used the sample code given with your link it inserted a line without any problem. I really think the problem is because after I run the script the database open in read only mode...
I'll post my two fonctions I use...
public bool Connection(string strNomDUtilisateur, string strHashMotDePasse) { string strConnecAccess; string strSQL;
strNomDUtilisateur.Replace("\"","\\\"");
OleDbConnection objConnectionAccess; OleDbDataAdapter objContenuRequete; DataSet objDataSetUtilisateur = new DataSet(); DataTable objDataTable;
strConnecAccess = "Provider=Microsoft.Jet.OLEDB.4.0; "; strConnecAccess += "Data Source="+ @HttpContext.Current.Request.PhysicalApplicationPath + @"charles\test6\MontrealEnLigne.mdb; "; strConnecAccess += "Persist Security Info=False";
objConnectionAccess = new OleDbConnection(strConnecAccess);
strSQL = "SELECT * FROM tblUtilisateur " + "WHERE UTIL_NOMDUTILISATEUR='" + strNomDUtilisateur + "' AND UTIL_MOTDEPASSE='" + strHashMotDePasse + "'"; objContenuRequete = new OleDbDataAdapter(strSQL, objConnectionAccess); objContenuRequete.Fill(objDataSetUtilisateur, "tblUtilisateur");
objDataTable = objDataSetUtilisateur.Tables["tblUtilisateur"];
if(objDataTable.Rows.Count == 1) { _strNomDUtilisateur = strNomDUtilisateur; _strHashMotDePasse = strHashMotDePasse; _strPrenom = objDataTable.Rows[0]["UTIL_PRENOM"].ToString(); _strNom = objDataTable.Rows[0]["UTIL_NOM"].ToString(); objConnectionAccess.Close(); return true; } else { _strNomDUtilisateur = null; _strHashMotDePasse = null; _strPrenom = null; _strNom = null; objConnectionAccess.Close(); return false; } } public string ChangerMotDePasse(string strAncHashMotDePasse, string strNouvHashMotDePasse, string strConfHashMotDePasse) { string strSQL; string strConnecAccess; OleDbConnection objConnectionAccess; OleDbDataAdapter objContenuRequete; DataSet objDataSetUtilisateur = new DataSet(); DataTable objDataTable; strConnecAccess = "Provider=Microsoft.Jet.OLEDB.4.0; "; strConnecAccess += "Data Source="+ @HttpContext.Current.Request.PhysicalApplicationPath + @"charles\test6\MontrealEnLigne.mdb;User Id=admin;Password=;"; objConnectionAccess = new OleDbConnection(strConnecAccess); if(_strNomDUtilisateur != null) { if(strNouvHashMotDePasse == strConfHashMotDePasse) { if(strAncHashMotDePasse == _strHashMotDePasse) { objConnectionAccess = new OleDbConnection(strConnecAccess); objConnectionAccess.Open(); strSQL = "UPDATE tblUtilisateur SET UTIL_MOTDEPASSE='" + strNouvHashMotDePasse + "' WHERE UTIL_NOMDUTILISATEUR='" + _strNomDUtilisateur + "' AND UTIL_MOTDEPASSE='" + strAncHashMotDePasse + "'"; OleDbCommand myCommand = new OleDbCommand(strSQL,objConnectionAccess); myCommand.ExecuteNonQuery(); objConnectionAccess.Close(); return strSQL; } } } return "abc"; }
|
|
Reply By:
|
Imar
|
Reply Date:
|
12/30/2005 4:20:07 PM
|
What do you get when you dump the contents of the variable strConnecAccess to a Label or TextBox??
Imar --------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
chafor
|
Reply Date:
|
1/5/2006 10:18:58 AM
|
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\goodpath\charles\test6\MontrealEnLigne.mdb;User Id=admin;Password=;
|
|
Reply By:
|
Imar
|
Reply Date:
|
1/5/2006 3:52:29 PM
|
Is that the correct path to the database you're using?
And did you add the right account to the test6 folder and give it write permissions? What account did you add??
Imar --------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
chafor
|
Reply Date:
|
1/6/2006 11:23:09 AM
|
Yes to both question..., but now I'm sure the problem is with IIS because when I try it on my machine... (I was on our intranet before) It's work...
Thanks for you're help Imar.
Chafor
|