2017-10-16 19 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文章。

相关问题