我正在尝试通过实体框架连接到 Azure SQL 数据库,连接字符串类似于以下内容:
Data Source=<server>.database.windows.net;Authentication=Active Directory Integrated;Initial Catalog=<database>
连接尝试是在 AutoCAD 2018 中运行的托管 WPF 表单的上下文中进行的。该项目是使用 .NET Framework 4.6 和 EF 6.1.3 生成的。
我遇到以下错误:
Unable to load adalsql.dll (Authentication=ActiveDirectoryIntegrated). Error code: 0x2. For more information, see http://go.microsoft.com/fwlink/?LinkID=513072
不幸的是,帮助链接不会指向提供此问题的技术详细信息的页面。到目前为止,我还没有在网上发现任何阐明根本原因的东西。
我也尝试过这个连接字符串:
Server=tcp:<server>.database.windows.net,1433;Initial Catalog=<database>;Persist Security Info=False;User ID=<username>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Integrated"
它是从 Azure 门户的ADO.NET (Active Directory integrated authentication)
部分复制的。但是,使用此连接字符串,我收到以下错误Cannot use 'Authentication=Active Directory Integrated' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords
但它不包含密码段。删除User ID
段后,我仍然收到Unable to load adalsql.dll ...
错误。
连接字符串Server=<server>.database.windows.net,1433; Authentication=Active Directory Integrated; Initial Catalog=<database>;
如果您遵循此技巧,则有效:
/// <summary>
/// HACK: Refer to https://stackoverflow.com/a/19130718/852956
/// </summary>
public void FixEfProviderServicesProblem() {
//The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
//for the 'System.Data.SqlClient' ADO.NET provider could not be loaded.
//Make sure the provider assembly is available to the running application.
//See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
SqlProviderServices instance = SqlProviderServices.Instance;
}