英文:
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.
"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?
答案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[] { "https://database.windows.net//.default" }),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[] { "https://database.windows.net//.default" }),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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论