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

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

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.

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

I am getting the below error

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.

&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

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方法如下:

protected override IDbConnection CreateNativeConnection()
{
    var conn = new SqlConnection(ConnectionString);
    var credential = new Azure.Identity.DefaultAzureCredential();
    var token = credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { &quot;https://database.windows.net//.default&quot; }),default);
    return conn;
}
```"

<details>
<summary>英文:</summary>

Looks like there is a way to customize creating the database context in Kentico.

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

I followed the steps mentioned in the above article and then modified the `DataConnection` class, `CreateNativeConnection` method as below

    protected override IDbConnection CreateNativeConnection()
    {
    	var conn = new SqlConnection(ConnectionString);
    	var credential = new Azure.Identity.DefaultAzureCredential();
    	var token = credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { &quot;https://database.windows.net//.default&quot; }),default);
    	return conn;
    }

</details>



# 答案2
**得分**: 0

我会尝试在Google或MSDN页面上搜索,因为这与Azure SQL更相关,而不是Kentico。例如,我找到了这个链接:[教程:使用Windows VM系统分配的托管标识访问Azure SQL][1]  [Azure SQL的Azure AD托管标识][2],看起来你需要使用Azure AD。本地标识可能不受支持。我建议向Azure SQL支持部门咨询

[1]: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-sql
[2]: https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql

<details>
<summary>英文:</summary>

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]
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. 


  [1]: https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-sql
  [2]: https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql

</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:

确定