C# 如何解决 Azure“此版本的 SQL Server 不支持 Windows 登录”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9818354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 10:44:28  来源:igfitidea点击:

How to resolve Azure "Windows logins are not supported in this version of SQL Server"?

c#sql-serverasp.net-mvcentity-frameworkazure-sql-database

提问by Just2Click

I get the following error message, when I try to connect to SQL Azure.

当我尝试连接到 SQL Azure 时,我收到以下错误消息。

Windows logins are not supported in this version of SQL Server

此版本的 SQL Server 不支持 Windows 登录

I'm using an Azure connection string. On development I'm running against SQL Server Express. This specific error is thrown when I try to fetch some data from the database.

我正在使用 Azure 连接字符串。在开发中,我正在运行 SQL Server Express。当我尝试从数据库中获取一些数据时会抛出这个特定的错误。

The context that I'm using is running in a using clause, see below

我使用的上下文在 using 子句中运行,见下文

function List<SomeType> GetList(string dbContextName) 
{ 
    using (MyDbContext context = new MyDbContext) 
    {
         return context.SomeTypes.ToList();
    } 
}

We're using Entity Framework version 4.2, ASP.NET MVC 3 and .NET 4.0.

我们使用 Entity Framework 4.2、ASP.NET MVC 3 和 .NET 4.0。

How can I resolve this issue?

我该如何解决这个问题?

回答by ryancrawcour

Integrated authentication (i.e. SSPI in the connection string) is NOT supported in SQL Azure. Only SQL Authentication is supported (i.e. username & password in the connection string)

SQL Azure 不支持集成身份验证(即连接字符串中的 SSPI)。仅支持 SQL 身份验证(即连接字符串中的用户名和密码)

回答by astaykov

Az already mentioned by others, only SQL Server authentication is supported in SQL Azure. You can read more on Guidelines and Limitations with SQL Azure. As well as the Security Guidelines and limitations for SQL Azure.

其他人已经提到过,SQL Azure 中仅支持 SQL Server 身份验证。您可以阅读有关SQL Azure 的准则和限制的更多信息。以及SQL Azure安全指南和限制

You have to CREATE LOGINby yourself in your MASTER database, then you will want to CREATE USERin your custom Azure Database. Also do not forget to execute sys.sp_addrolemember to grant some permissions to your user.

您必须自己在 MASTER 数据库中创建登录,然后您需要在自定义 Azure 数据库中创建用户。另外不要忘记执行 sys.sp_addrolemember 来授予您的用户一些权限。

More on managing users and logins in SQL Azurecan be found here.

可以在此处找到有关在 SQL Azure 中管理用户和登录名的更多信息

And, at the end, you can always look at the invaluable source for connection strings.

而且,最后,您始终可以查看连接字符串的宝贵来源。

回答by JoshYates1980

I was using user/pass and still got the error message. But, I added this to my connection string and it worked.

我正在使用 user/pass 并且仍然收到错误消息。但是,我将它添加到我的连接字符串中并且它起作用了。

Trusted_Connection=False;Encrypt=True;

回答by Mahmad Khoja

Set

Integrated Security=False

In Connection String.

在连接字符串中。

回答by Joseph Wu

You've probably used the incorrect connection string, this is the connection string format that worked for my case:

您可能使用了不正确的连接字符串,这是适用于我的案例的连接字符串格式:

"ConnectionString": "Server=tcp:xxxx.database.windows.net,1433;Database=xxx;User ID=xxx;Password=xxx;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

"ConnectionString": "Server=tcp:xxxx.database.windows.net,1433;Database=xxx;User ID=xxx;Password=xxx;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

回答by Shetty

1.**Windows Authentication** is not supported in Azure so you should go with **SQL Server Authentication**.
2.When you use SQL server Authentication you should pass User Id(Login in SQL server) and Password(Password in SQL server).
3.User Id should contain space in between should not be like UserId.
4.Trusted_Connection should be false.
The connection string in *appsettings.json* look like this:

"ConnectionStrings": {
    "DBContext": "Server=ServerName;Database=DbName;User Id=loginName;Password=loginPassword;Trusted_Connection=false;MultipleActiveResultSets=true"
  }