OleDBException: Duplicate Values in one place but not another RRS feed

  • Question

  • I have an application where in one form I can call a method to insert a record and everything is all well. I have a class that I try to call the same method with the same query string and it gives me this error:

    Code Snippet

    System.Data.OleDb.OleDbException: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
    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.ExecuteNonQuery()
    at QuaintDesigns.ERGC.CashClose.CloseoutDBI.insertCloseout(Closeout closeout) in C:\Documents and Settings\Main\My Documents\Visual Studio 2005\Projects\CashClose\CashCloseLib\CloseoutDBI.cs:line 94

    tThis doesnt make sense to me because the table is empty when I call this method so there should be no duplicates.

    Can anyone make sense of this?

    Tuesday, July 24, 2007 12:54 AM

All replies

  • Well after a few hours of trying random things i tried another random idea of changing the connection string from:

    Code Snippet

    this._connString = "provider=Microsoft.Jet.OLEDB.4.0;data source=.\\myDatabase.mdb";


    Code Snippet

    this._connString = "provider=Microsoft.Jet.OLEDB.4.0;data source=C:\\Documents and Settings\\Main\\My Documents\\Visual Studio 2005\\Projects\\app\\bin\\Debug\\myDatabase.mdb";

    Now this seems to work calling it from both my classes. Now to the tough part, what was the problem to begin with, how and why did this fix my issue?

    Tuesday, July 24, 2007 3:00 AM

  • Any chance you have multiple copies of your database and that you weren't looking at the one you thought you were?
    Tuesday, July 24, 2007 12:43 PM
  • I don't think so... but I could be wrong. Regardless with the first connection string it should have been connecting to the db I had in the build directory (I Think). I was running the same sql statement in the sql window of the same database in the build directory and it was working. Also when I would run the same sql statement through the same method but from a different class it would work. I'm stumped but then I'm new to ADO.NET and C#.

    Thanks for the input
    Tuesday, July 24, 2007 8:08 PM