VS 2012 Database Project “unresolved reference to object” Error

后端 未结 9 1255
再見小時候
再見小時候 2020-12-16 09:02

I created SQL Server Database Project in VS 2012 & imported our database. When I build the project, I get a lot of \"unresolved reference to object\" Errors. These error

相关标签:
9条回答
  • 2020-12-16 09:40

    In my case, the function that couldn't be found was of Build Action=None and so it wasn't being included in the compile.

    Changing the Build Action to Build corrected this.

    0 讨论(0)
  • 2020-12-16 09:40

    You will also get this error when you add a table (using .sql file ) and if you do not check-in the .sqlproj file

    0 讨论(0)
  • 2020-12-16 09:46

    It is possible that the objects are inside NotInBuild tag in the project file for naming or other issue. In my case I saved the file with ..sql and the extra dot was causing it to move under NotInBuild tag inside project file. I corrected the extension and moved the missing object under build tag and that resolved the issue.

    0 讨论(0)
  • 2020-12-16 09:48

    To reference another sqlproj's schema and use three-part naming, modify your .sqlproj file to add a DatabaseVariableLiteralValue element on the referenced project.

    In within the element like <ProjectReference Include="..\SomeDatabaseProject\SomeDatabaseProject.sqlproj">, add the following:

    <DatabaseVariableLiteralValue>SomeDatabaseProject</DatabaseVariableLiteralValue>

    For example:

        <ProjectReference Include="..\SomeDatabaseProject\SomeDatabaseProject.sqlproj">
          <Name>SomeDatabaseProject</Name>
          <Project>{some-project-guid}</Project>
          <Private>True</Private>
          <DatabaseVariableLiteralValue>SomeDatabaseProject</DatabaseVariableLiteralValue>
        </ProjectReference>
    

    Then you can use clean, three-part naming references like SomeDatabaseProject.SomeSchema.SomeTable.

    0 讨论(0)
  • 2020-12-16 09:49

    Try explicitly defining the class:

    class: Specifies the class of the securable on which the permission is being granted. The scope qualifier :: is required.

    Read the docs on the SQL GRANT statement: http://technet.microsoft.com/en-us/library/ms187965.aspx

    In my case I had a User Defined Table Type.

    GRANT EXECUTE ON TYPE::[dbo].[MessageTableType] TO [PostOffice_Role];
    
    0 讨论(0)
  • 2020-12-16 09:54

    This may be an edge case but if in your object definition you are also documenting the object (we do, anyway...) using sp_addextendedproperty you can also get this error if you have stated an incorrect object type - which can happen if copy & pasting. The "unresolved reference to object" error makes sense here when you think about it.

    For example the following will recreate the error as the level1type should be 'PROCEDURE' and not 'FUNCTION'.

    EXEC sp_addextendedproperty
      @name = N'MS_Description',
      @value = N'Description of the stored procedure...',
      @level0type = N'SCHEMA',
      @level0name = N'dbo',
      @level1type = FUNCTION',
      @level1name = N'spMyStoredProcedureName'
    GO
    
    0 讨论(0)
提交回复
热议问题