I have an C# form application that use an access database.
This application works perfectly in debug and release. It works on all version of Windows.
But it crash on one computer with Windows 7.
The message I got is:
System.Data.OleDb.OleDbException: No value given for one or more required parameters.
EDIT, after some debugging with messagebox on the computer that have the problem, here is the code that bug.The error is catched on the cmd.ExecuteReader(). The messagebox juste before is shown and the next one is the one in the catch with the exception below. Any ideas?
public List<CoeffItem> GetModeleCoeff()
{
List<CoeffItem> list = new List<CoeffItem>();
try
{
OleDbDataReader dr;
OleDbCommand cmd = new OleDbCommand("SELECT nIDModelAquacad, nIDModeleBorne, fCoefficient FROM tbl_ModelBorne ORDER BY nIDModelAquacad", m_conn);
MessageBox.Show("Commande SQL créée avec succès");
dr = cmd.ExecuteReader();
MessageBox.Show("Exécution du reader sans problème!");
while (dr.Read())
{
list.Add(new CoeffItem(Convert.ToInt32(dr["nIDModelAquacad"].ToString()),
Convert.ToInt32(dr["nIDModeleBorne"].ToString()),
Convert.ToDouble(dr["fCoefficient"].ToString())));
}
MessageBox.Show("Lecture du reader");
dr.Close();
MessageBox.Show("Fermeture du reader");
}
catch (OleDbException err)
{
MessageBox.Show("Erreur dans la lecture des modèles/coefficient: " + err.ToString());
}
return list;
}
I think it’s something related to the connection string but why only on that computer.
Thanks for your help!
EDIT
Here is the complete error message:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Data.OleDb.OleDbException: No value given for one or more required parameters.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at DatabaseLayer.DatabaseFacade.GetModeleCoeff()
at DatabaseLayer.DatabaseFacade.InitConnection(String strFile)
at CalculatriceCHW.ListeMesure.OuvrirFichier(String strFichier)
at CalculatriceCHW.ListeMesure.nouveauFichierMenu_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Ok, here is what happened.
The database missed 2 column in one table. The reason? Well, in the application, when the user click on “New”, a copy is made of the .mdb in the application folder to the location of the choice of the user. The “model” database is ok, all the column are there, but the copied file was missing 2 column. So I did a little research, a found that the application was using the Virtual Store of Windows 7 instead of the program file directory. Why? We think that the user saved the file right in the program file directory (something that cause a copy in the virtual store) with the old version of the app (and of the database). At this moment, the virtual store was used in priority to the program file and everything was not working.
So thanks for all your help, it help me find the problem!