2017-10-16 24 views
0

我有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服務器上使用用戶數據庫的主數據庫功能,是否有解決方案?

+0

爲什麼使用EXEC insted的SELECT?請仔細閱讀,選擇master.dbo.fn_varbintohexstr(123) – sepupic

+0

@sepupic。使用exec的示例僅用於獲取更適當的錯誤消息。選擇也不起作用。 –

+0

https://stackoverflow.com/questions/11284998/cant-query-between-databases-in-sql-azure – sepupic

回答

2

您不能在SQL Azure上使用三個或四個部件名稱進行分佈式數據庫查詢。

對於跨SQL Azure中多個數據庫的查詢,您需要使用彈性查詢。有關更多信息,請訪問this文章。

相關問題