We have a single table-value function that causes the dacpac to fail when created with Error SQL71561 (unresolved reference). Like many of the other functions in the same database, this one references a table in another database on the same server. Unlike the other functions, this one consistently causes the dacpac to fail.
I’ve tried using 4-part names to reference the table, and I’ve also created a synonym. Neither seem to work, and I’m now at a complete loss. I can’t finding enough information online, and I don’t get enough feedback from SQL to properly troubleshoot the error. Can someone help point me in the right direction?
Details below:
We have a single instance of SQL Server 2014 enterprise that contains 3 separate databases named [dbParks], [dbLandmarks], and [dbPeople]. The server name is [sCity2].
Inside the [dbParks] database is a table-value function [fn_GetEmployeeList] that contains a reference to [dbPeople].[dbo].[Employees]. This function consistently errors with:
Error SQL71561: Error validating element [dbo].[fn_GetEmployeeList]: Function: [dbo].[fn_GetEmployeeList] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [sCity2].[dbPeople].[dbo].[Employees].[a] or [sCity2].[dbPeople].[dbo].[Employees].[EmployeeCode].
I updated the function (below) to use a 4-part name instead of the 3-part name when referencing the table, and it still failed:
CREATE FUNCTION [dbParks].[dbo].[fn_GetEmployeeList] ( )
RETURNS TABLE
AS
RETURN (
SELECT
a.EmployeeCode,
a.MunicipleCode,
a.FullName,
a.Supervisor
FROM
[sCity2].[dbPeople].[dbo].[Employees] a
)
GO
I then created a synonym that references [dbPeople].[dbo].[Employees] named syn_Employees, which also causes the dacpac to fail during creation.
CREATE FUNCTION [dbParks].[dbo].[fn_GetEmployeeList] ( )
RETURNS TABLE
AS
RETURN (
SELECT
a.EmployeeCode,
a.MunicipleCode,
a.FullName,
a.Supervisor
FROM
[dbo].[syn_Employees] a
)
GO
What’s really confusing is that there are other functions in the same database that use synonyms and 3-part name references that don’t cause the dacpac to fail. Also, when I remove the [fn_GetEmployeeList] the dacpac is created successfully.
Any help is truly appreciated