我有Azure SQL數據庫服務器+一個Azure SQL數據庫。在這個數據庫中,我有一些函數調用主DB的一些函數作爲其邏輯的一部分。從同一個Azure SQL Server上的其他數據庫調用主數據庫的功能
例子:
CREATE FUNCTION [dbo].[EncryptByKey]
(
@EncryptionKeyId nvarchar(1024),
@ValueToEncrypt varchar(MAX)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
RETURN master.dbo.fn_varbintohexstr(ENCRYPTBYKEY(Key_GUID(@EncryptionKeyId), @ValueToEncrypt))
END
給我一個錯誤:
Cannot find either column "master" or the user-defined function or aggregate "master.dbo.fn_varbintohexstr", or the name is ambiguous.
相反,如果我嘗試:
exec master.dbo.fn_varbintohexstr(123)
我得到的錯誤是:
Reference to database and/or server name in 'master.dbo.fn_varbintohexstr' is not supported in this version of SQL Server.
關於如何在Azure SQL服務器上使用用戶數據庫的主數據庫功能,是否有解決方案?
爲什麼使用EXEC insted的SELECT?請仔細閱讀,選擇master.dbo.fn_varbintohexstr(123) – sepupic
@sepupic。使用exec的示例僅用於獲取更適當的錯誤消息。選擇也不起作用。 –
https://stackoverflow.com/questions/11284998/cant-query-between-databases-in-sql-azure – sepupic