开发者

Pass tenant id via sql server connection

开发者 https://www.devze.com 2022-12-30 19:25 出处:网络
I\'m building m开发者_如何学Pythonulti tenant application with shared table structure using Microsoft SQL Server.

I'm building m开发者_如何学Pythonulti tenant application with shared table structure using Microsoft SQL Server.

I wonder if it possible to pass tenantID parameter via sql server connection. I don't want to create separate user account for each tenant.

Currently I see two ways: via ApplicationName or WorkstationID

Best regards, Alexey Zakharov


I would use the Application Name of the connect string, which is then easy to get at in TSQL with APP_NAME (Transact-SQL).

However, you could also consider using CONTEXT_INFO (Transact-SQL).

--to set value
DECLARE @CONTEXT_INFO  varbinary(128)
SET @CONTEXT_INFO =cast('Anything Here!!'+REPLICATE(' ',128) as varbinary(128))
SET CONTEXT_INFO @CONTEXT_INFO


--to use value
IF CAST(CONTEXT_INFO() AS VARCHAR(128))='Anything Here!'
BEGIN
    --do something
END
0

精彩评论

暂无评论...
验证码 换一张
取 消