none
Primary Key Already Exists RRS feed

  • Question

  • I am using C# to link sql server tables into access 2000 databases.  I am assigning a primary key through the link in process, but sometimes I get this error

    System.Runtime.InteropServices.COMException (0x800A0CD3): Primary Key already exists at DAO.Database.Execute(String Query, Object Options)

    This is the syntax I am using, and it is the 1st instance of me attempting to link in the table.  If I open the table it is not read only, and all proper key has been assigned.  I am just mindblown as to why the error is thrown -- and it is thrown once the dd.Execute line is hit.

    DAO.Database dd;
    DAO.DBEngine db = new DAO.DBEngine();
    DAO.TableDef tdf1;
    
    string sqlconnectionstring = ""; //SQL Connection is here
    
    string PK1 = "Create Unique Index CustomerID On table1 (CustomerID) With Primary";;
    
    string SqlTableName = "dbo.CustomerInformation";
    string AccessTableName = "Customer_Information";
    
    dd = db.OpenDatabase("A:\\Databases\\Production\\database1.mdb");
    tdf1 = dd.CreateTableDef(AccessTableName);
    tdf1.Connect = sqlconnectionstring;
    tdf1.SourceTableName = sqlTableName;
    dd.TableDefs.Append(tdf1);
    dd.Execute(PK1);
    
    

    Monday, April 6, 2015 4:01 PM

Answers

  • When during the linked table creation process a primary key could be determined, then Jet/DAO creates the primary key on the linked table itself. This happens for all linked tables pointing to a table which has a primary key defined.

    When you create a linkied table on a view, then you need to create the primary key for Access manually to make the view updatable.

    Monday, April 6, 2015 5:18 PM

All replies

  • When during the linked table creation process a primary key could be determined, then Jet/DAO creates the primary key on the linked table itself. This happens for all linked tables pointing to a table which has a primary key defined.

    When you create a linkied table on a view, then you need to create the primary key for Access manually to make the view updatable.

    Monday, April 6, 2015 5:18 PM
  • If I am linking in a table Jet/DAO can determine the PK, but if it is a view the PK has to be manually assigned. 

    Am I understanding that correctly?

    Monday, April 6, 2015 5:56 PM
  • Correct.

    Monday, April 6, 2015 9:03 PM