rr-wfm / MSBuild.Sdk.SqlProj

An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
MIT License
408 stars 46 forks source link

Support for linked servers #482

Closed marcadella closed 2 months ago

marcadella commented 11 months ago

I get a lot of unresolved references to resources living on a linked server. Is there a way to define the linked server in the project? Or is there a way to somehow ignore such errors?

ErikEJ commented 11 months ago

Please share the exact errors you get

marcadella commented 11 months ago

Given the sql: ... from LBR_ROLLE P join [ILPROD2]..[LBR].[LBR_ROLLE] L on L.id = P.id, I get: "error SQL71501: SqlView: [dbo].[vPROD_LBR_ROLLE_DIFF] 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: [dbo].[LBR_ROLLE].[L]::[ID], [ILPROD2].[].[LBR].[LBR_ROLLE].[ID] or [ILPROD2].[].[LBR].[LBR_ROLLE].[L]::[ID]." I don't really see why [ILPROD2]..[LBR].[LBR_ROLLE] is ambiguous and it looks like the model doesn't know how to handle ILPROD2 which is a linked server.

ErikEJ commented 11 months ago

Have a look here: https://github.com/rr-wfm/MSBuild.Sdk.SqlProj#package-references

marcadella commented 11 months ago

Thanks for your answer. The thing is that I don't have any .dacpac for that linked server. Is it somehow possible to tell the tool to ignore missing dependencies for this linked server? I see in the doc that one can use SuppressMissingDependenciesErrors, but it looks like it only works with a package or project reference, but in my case I have none.

ErikEJ commented 6 months ago

The approach for working with linked servers is a dacpac for the linked server objects as described here;

https://www.mssqltips.com/sqlservertip/3331/how-to-use-a-linked-server-in-a-sql-server-database-project/

ErikEJ commented 2 months ago

Closing as there are ways to do this.