0

I have an Asp.Net MVC webapp and I get the following error when I try to create a new Azure SQL user for the DefaultConnection.

[SqlException (0x80131904): Login failed for user 'myNewSQLuser'.]

On SQL Server Object Explorer I connected to the master database using the Server Admin login and I created a login for the new user with:

CREATE LOGIN myNewSQLuser WITH PASSWORD = 'myNewPwd';

Then with the same Sever Admin login I connected to the database corresponding to the webapp and created the user:

CREATE USER myNewSQLuser FROM LOGIN myNewSQLuser;

and then:

ALTER ROLE db_owner ADD MEMBER myNewSQLuser;

Then, on the web publish profile I have the following connection string:

Data Source=tcp:mydbserver.database.windows.net,1433;Initial Catalog=myAzureSqlDB;Persist Security Info=False;User ID=myNewSQLuser;Password=myNewPwd;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False

When on Visual Studio, Edit Publish Profile, I am able to successfully test the connection string.

When I publish the MVC webapp to Azure App Service I see the "Login Failed" error mentioned above. However I am able to use the credentials for myNewSQLuser to connect to the database for example from Azure DataStudio.

donquijote
  • 1,562
  • 5
  • 18
  • 41
  • Which authentication you used for login Azure SQL? Can this blog https://stackoverflow.com/questions/22415319/system-data-sqlclient-sqlexception-login-failed-for-user helpful? – Leon Yue Sep 02 '19 at 07:00
  • Thanks @LeonYue. The web app is able to connect to the Azure SQL database if I use the Azure SQL server admin user in the connection string instead of "myNewSQLuser". Currently on the web app Web.config I have – donquijote Sep 02 '19 at 12:06
  • Maybe you can try to add the authentication and test. Did you solved it now? – Leon Yue Sep 05 '19 at 01:05
  • I tried changing to on Web.Config and this didn't solve it. The issue still remains unresolved. – donquijote Sep 05 '19 at 10:46

0 Answers0