简体   繁体   English

Azure上的SQL Server中的用户'san'登录失败

[英]Login failed for user 'san' in SQL Server on Azure

I keep getting an error 我一直在收到错误

Login failed for user 'san' 用户'san'登录失败

while using Azure database from Web API with Entity Framework. 使用带有Entity Framework的Web API中的Azure数据库。

Here is the screen shot of SSMS. 这是SSMS的屏幕截图。 I am able to access the database from SSMS, but not from the Web API database call. 我能够从SSMS访问数据库,但不能从Web API数据库调用访问。

ssms的形象

I tried to create a new login and user but getting an error 我试图创建一个新的登录和用户,但收到错误

User already exists 用户已存在

The same problem has been ask in the below link but those solution did not work for me 在下面的链接中已经提出了同样的问题,但这些解决方案对我不起作用

https://dba.stackexchange.com/questions/141239/login-failed-for-user-on-sql-azure-from-azure-hosted-web-application https://dba.stackexchange.com/questions/141239/login-failed-for-user-on-sql-azure-from-azure-hosted-web-application

Azure SQL - Login failed for user Azure SQL - 用户登录失败

https://dba.stackexchange.com/questions/102605/azure-sql-database-login-failed-for-user-in-application-but-works-fine-in-ssm https://dba.stackexchange.com/questions/102605/azure-sql-database-login-failed-for-user-in-application-but-works-fine-in-ssm

Here is the connection string 这是连接字符串

"DefaultConnection": "Server=tcp:fetessbird.datatable.windows.net,1433;Initial Catalog=Falcon;Persist Security Info=True;User ID=san;Password=*****;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

I am able to access the database from SSMS not from the webapi 我可以从SSMS访问数据库,而不是从webapi访问

Connect to the Falcon database using SQL Server Management Studio and run the following statements. 使用SQL Server Management Studio连接到Falcon数据库并运行以下语句。

CREATE USER San FROM LOGIN San;
GO
EXEC sp_addrolemember 'db_owner', 'San';

You just create a LogIn named San on the server, what you need now is to create a user related to this LogIn in the Flcon database, you should give it permissions to the db. 您只需在服务器上创建一个名为SanLogIn ,现在您需要在Flcon数据库中创建与此LogIn相关的用户,您应该赋予它对db的权限。

Go to Falcon -> Users -> RightClick -> New user 转到Falcon - >用户 - > RightClick - >新用户

then follow the wizard. 然后按照向导。

Update: 更新:

To create the user: 要创建用户:

CREATE USER San FOR LOGIN San WITH DEFAULT_SCHEMA = Falcon;  
GO 

Then you can give it rights as(if you already have the user the just give it rights): 然后你可以赋予它权利(如果你已经让用户给它权利):

EXEC sp_addrolemember N'db_owner', N'San' 
GO

As from your screenshot the login san is created and valid on the SQL Server but you haven't given any permissions to the database you are connecting to from the API. 从屏幕截图开始, 登录 san在SQL Server上创建并且有效,但您没有从API连接到的数据库中获得任何权限。 The login san it's not an user on the database you want to access. 登录它不是您要访问的数据库上的用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM