如何使用托管标识将Kentico连接到Azure SQL数据库

huangapple go评论86阅读模式
英文:

How to connect Kentico to Azure SQL database using managed identity

问题

I am using Kentico 13 and trying to connect to the Azure SQL database using managed identity in my localhost environment using the below connection string.

  1. "Server=tcp:<MyServer>.database.windows.net,1433;Initial Catalog=<MyDB>;;Authentication=Active Directory Device Code Flow;"

I am getting the below error

  1. CMS.DataEngine.ApplicationInitException: 'Keyword not supported: 'authentication'.'

How can I get past this error or is there any other way to connect to the database using managed Identity?

英文:

I am using Kentico 13 and trying to connect to the Azure SQL database using managed identity in my localhost environment using the below connection string.

  1. &quot;Server=tcp:&lt;MyServer&gt;.database.windows.net,1433;Initial Catalog=&lt;MyDB&gt;;Authentication=Active Directory Device Code Flow;&quot;

I am getting the below error

  1. CMS.DataEngine.ApplicationInitException: &#39;Keyword not supported: &#39;authentication&#39;.&#39;

How can I get past this error or is there any other way to connect to the database using managed Identity?

答案1

得分: 1

以下是您要翻译的内容:

"看起来有一种自定义创建Kentico数据库上下文的方法。

https://docs.xperience.io/custom-development/customizing-providers/custom-data-provider-example

我按照上述文章中提到的步骤,然后修改了DataConnection类的CreateNativeConnection方法如下:

  1. protected override IDbConnection CreateNativeConnection()
  2. {
  3. var conn = new SqlConnection(ConnectionString);
  4. var credential = new Azure.Identity.DefaultAzureCredential();
  5. var token = credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { &quot;https://database.windows.net//.default&quot; }),default);
  6. return conn;
  7. }
  8. ```"
  9. <details>
  10. <summary>英文:</summary>
  11. Looks like there is a way to customize creating the database context in Kentico.
  12. https://docs.xperience.io/custom-development/customizing-providers/custom-data-provider-example
  13. I followed the steps mentioned in the above article and then modified the `DataConnection` class, `CreateNativeConnection` method as below
  14. protected override IDbConnection CreateNativeConnection()
  15. {
  16. var conn = new SqlConnection(ConnectionString);
  17. var credential = new Azure.Identity.DefaultAzureCredential();
  18. var token = credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { &quot;https://database.windows.net//.default&quot; }),default);
  19. return conn;
  20. }
  21. </details>
  22. # 答案2
  23. **得分**: 0
  24. 我会尝试在Google或MSDN页面上搜索,因为这与Azure SQL更相关,而不是Kentico。例如,我找到了这个链接:[教程:使用Windows VM系统分配的托管标识访问Azure SQL][1] [Azure SQL的Azure AD托管标识][2],看起来你需要使用Azure AD。本地标识可能不受支持。我建议向Azure SQL支持部门咨询
  25. [1]: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-sql
  26. [2]: https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql
  27. <details>
  28. <summary>英文:</summary>
  29. I would try searching on Google or MSDN pages as this is more related to Azure SQL and not Kentico. E.g. I found this: [Tutorial: Use a Windows VM system-assigned managed identity to access Azure SQL][1]
  30. or [Managed identities in Azure AD for Azure SQL][2] and as it looks like, you need to use Azure AD. Local identities are probably not supported. I would maybe ask Azure SQL support.
  31. [1]: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-sql
  32. [2]: https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql
  33. </details>

huangapple
  • 本文由 发表于 2023年4月7日 00:59:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定