System.Data.SqlClient.SqlException (0x80131904): Either the parameter @objname is ambiguous or the claimed @objtype (OBJECT) is wrong

0

I am trying to modify a SQL Server table using Entity Framework model and I get this error:

Either the parameter @objname is ambiguous or the claimed @objtype (OBJECT) is wrong

How can I solve this issue?

I used below commands to do that.

 Add-Migration "comments", 
 Update-Database


PM> Update-Database -Verbose
Using StartUp project 'API'.
Using NuGet project 'Data'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'template' (DataSource: localhost, Provider: System.Data.SqlClient, Origin: Configuration).
Applying explicit migrations: [201905201819586_HandoverNote].
Applying explicit migration: 201905201819586_HandoverNote.
EXECUTE sp_rename @objname = N'dbo.HandoverNotes', @newname = N'HandoverNotes', @objtype = N'OBJECT'
IF object_id('[PK_dbo.HandoverNotes]') IS NOT NULL BEGIN
    EXECUTE sp_rename @objname = N'[PK_dbo.HandoverNotes]', @newname = N'PK_dbo.HandoverNotes', @objtype = N'OBJECT'
END
System.Data.SqlClient.SqlException (0x80131904): Either the parameter @objname is ambiguous or the claimed @objtype (OBJECT) is wrong.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)

Code:

namespace Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class HandoverNote : DbMigration
    {
        public override void Up()
        {
            RenameTable(name: "dbo.HandoverNotes", newName: "HandoverNotes");
            DropForeignKey("dbo.HandoverNotes", "BusinessUnitID", "dbo.BusinessUnit");
            DropIndex("dbo.HandoverNotes", new[] { "BusinessUnitID" });
            DropPrimaryKey("dbo.HandoverNotes");
            AddColumn("dbo.HandoverNotes", "RecID", c => c.Int(nullable: false, identity: true));
            AddColumn("dbo.HandoverNotes", "message", c => c.String());
            AddColumn("dbo.HandoverNotes", "LastUpdatedDate", c => c.DateTime(nullable: false));
            AddColumn("dbo.HandoverNotes", "BusinessUnit", c => c.String());
            AlterColumn("dbo.HandoverNotes", "CreatedBy", c => c.String());
            AddPrimaryKey("dbo.HandoverNotes", "RecID");
            DropColumn("dbo.HandoverNotes", "ID");
            DropColumn("dbo.HandoverNotes", "BusinessUnitID");
            DropColumn("dbo.HandoverNotes", "ParentNoteID");
            DropColumn("dbo.HandoverNotes", "AssetID");
            DropColumn("dbo.HandoverNotes", "Description");
            DropColumn("dbo.HandoverNotes", "Status");
            DropColumn("dbo.HandoverNotes", "UpdatedDate");
            DropColumn("dbo.HandoverNotes", "UpdatedBy");
        }

        public override void Down()
        {
            AddColumn("dbo.HandoverNotes", "UpdatedBy", c => c.String(nullable: false, maxLength: 255));
            AddColumn("dbo.HandoverNotes", "UpdatedDate", c => c.DateTime(nullable: false));
            AddColumn("dbo.HandoverNotes", "Status", c => c.String());
            AddColumn("dbo.HandoverNotes", "Description", c => c.String());
            AddColumn("dbo.HandoverNotes", "AssetID", c => c.String());
            AddColumn("dbo.HandoverNotes", "ParentNoteID", c => c.Int(nullable: false));
            AddColumn("dbo.HandoverNotes", "BusinessUnitID", c => c.Int(nullable: false));
            AddColumn("dbo.HandoverNotes", "ID", c => c.Int(nullable: false, identity: true));
            DropPrimaryKey("dbo.HandoverNotes");
            AlterColumn("dbo.HandoverNotes", "CreatedBy", c => c.String(nullable: false, maxLength: 255));
            DropColumn("dbo.HandoverNotes", "BusinessUnit");
            DropColumn("dbo.HandoverNotes", "LastUpdatedDate");
            DropColumn("dbo.HandoverNotes", "message");
            DropColumn("dbo.HandoverNotes", "RecID");
            AddPrimaryKey("dbo.HandoverNotes", "ID");
            CreateIndex("dbo.HandoverNotes", "BusinessUnitID");
            AddForeignKey("dbo.HandoverNote", "BusinessUnitID", "dbo.BusinessUnit", "ID", cascadeDelete: true);
            RenameTable(name: "dbo.HandoverNotes", newName: "HandoverNote");
        }
    }
}
c#
sql-server
entity-framework
asked on Stack Overflow May 20, 2019 by Jayesh • edited May 20, 2019 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0