I have a stored procedure in a SQL Project running in JetBrains Rider which is defined as follows:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spGetDeviceNotification]
@SerialNumber NVARCHAR(60),
@ChannelID INT,
@DownloadTableName VARCHAR(200)
AS
-- Notes for testing
-- @SerialNumber and @ChannelID are set as default values for testing
-- But these can be overwritten
/********************
* Declare Variables *
*********************/
DECLARE
@ErrorLine INT,
@ErrorState INT,
@ErrorNumber INT,
@ErrorMessage NVARCHAR(4000),
@ErrorSeverity INT,
@ErrorProcedure NVARCHAR(200),
@RC INT,
@InputMessage NVARCHAR(4000),
@TableName NVARCHAR(60),
@SQLX NVARCHAR(4000),
@ArchiveInputFileName NVARCHAR(1000),
@ImportDelimiter VARCHAR(10),
@FileNameTimestamp NVARCHAR(100),
@FromDate DATETIME2,
@ToDate DATETIME2,
@Procname NVARCHAR(200),
@CreatedByUser UNIQUEIDENTIFIER
DECLARE @ErrorMessage_OUT NVARCHAR(4000)
/***********************
* Initialise Variables *
***********************/
SET @ErrorLine = 0
SET @ErrorState = 1
SET @ErrorNumber = 50000
SET @ErrorMessage = N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' + 'Message: '
SET @ErrorSeverity = 16
SET @ErrorProcedure = ISNULL(OBJECT_NAME(@@PROCID), '-')
SET @ProcName = @ErrorProcedure
SET @RC = 0
SET @CreatedByUser = [dbo].[fnReturnUserID] (SYSTEM_USER)
-- Extract FromDate from the first date in readin reading table
SET @sqlx = 'SELECT @FromDate = MIN(ReadingDateTime) FROM ' + Quotename(@DownloadTableName,'[]')
EXEC [dbo].[sp_executesql] @sqlx, N'@FromDate datetime out', @FromDate out
-- Extract FromDate from the first date in readin reading table
SET @sqlx = 'SELECT @ToDate = MAX(ReadingDateTime) FROM ' + Quotename(@DownloadTableName,'[]')
EXEC [dbo].[sp_executesql] @sqlx, N'@ToDate datetime out', @ToDate out
SET @FromDate = CONVERT(DATETIME2, CONVERT(varchar(11),@FromDate, 111 ) + ' 00:00:00', 111)
SET @ToDate = CONVERT(DATETIME2, CONVERT(varchar(11),@ToDate, 111 ) + ' 23:59:59', 111)
BEGIN TRY
SELECT
dn.DeviceNotificationID,
Dce.SerialNumber,
dc.ChannelID,
Dn.NotificationDate,
Dn.NotificationXML
FROM
[dbo].[Device] Dce
JOIN
[dbo].[DeviceChannel] Dc ON Dce.DeviceID = Dc.DeviceID
JOIN
[dbo].[DeviceNotification] Dn ON DC.DeviceChannelID = dn.DeviceChannelID
WHERE
SerialNumber = @SerialNumber
AND ChannelID = @ChannelID
AND NotificationDate >= ISNULL(@FromDate, NotificationDate)
AND NotificationDate <= ISUNLL(@ToDate, NotificationDate)
ORDER BY
NotificationDate
END TRY
BEGIN CATCH
-- Get Error Variables Values
SET @ErrorNumber = ERROR_NUMBER()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
SET @ErrorLine = ERROR_LINE()
SET @ErrorProcedure = @ProcName -- removed Error Procedure because it returns blank
-- Build ErrorMessage Variable Value
SET @ErrorMessage = @ErrorMessage + ERROR_MESSAGE()
SET @InputMessage = @ProcName + ': Process Failed. '+ @ErrorMessage
EXECUTE [Aud].[spSetSystemLog]
@SpName = @ProcName,
@Arguments = NULL,
@SystemLogMessage = @InputMessage,
@DMLRowsAffected = NULL,
@UserID = @CreatedByUser
RAISERROR (@ErrorMessage, @ErrorSeverity, 1, @ErrorNumber, @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine)
-- Exit stored procedure
END CATCH
SET NOCOUNT OFF
-- Exit stored procedure
RETURN @RC
Now upon building the SQL Project, I get the following warning:
spGetDeviceNotification.sql(95, 10): [SQL71502] SqlProcedure: [dbo].[spGetDeviceNotification] has an unresolved reference to object [dbo].[sp_executesql].
How can I get rid of this warning in this database project in JetBrains Rider?
I saw some suggestions of creating a database reference to the master database... this can be easily done in Visual Studio but not so easy in Rider.
But what I did was to amend the .csproj
file for my SQL project and added the following lines:
<ItemGroup>
<ArtifactReference Include="$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\130\SqlSchemas\master.dacpac">
<HintPath>$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\130\SqlSchemas\master.dacpac</HintPath>
<SuppressMissingDependenciesErrors>True</SuppressMissingDependenciesErrors>
<DatabaseVariableLiteralValue>master</DatabaseVariableLiteralValue>
</ArtifactReference>
</ItemGroup>
But still the SQL warning is there... How can I get rid of a warning for unresolved reference to object [dbo].[sp_executesql]
?