Azure Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'null' - sql

I wrote an app and I am trying upload it on Azure. The app runs ok locally and has a SQL Server database as the backend; the app is based off MVC.
When I try to access a page such as /person, I get this error:
Azure Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'null'.
Anyone ever dealt with such an error and how did you resolve it.
I have tried a few suggestions but none seems to work:
adding to config file
setting Persist Security Info=False to true
What is the best way to solve this?

On the app's data connection, the connection string had no userid. Adding a userid fixed the issue. Even though when the app was published with a proper connection string, the user id was empty.

Related

User login failed for <user> in production but same connection string works from local client

I have an Azure database setup of which I have included the below connection string as I believe it should be. Problem is when I try to run my client app in production, the server returns a 500 internal error. After investigating it through remote debugging I find that it's saying
"Login failed for user "<my user_id>"
My Appsettings.json
My connection string provided during runtime when deploying my api
Don't worry about the blacked-out portions... I've verified those to be the same in both.
Now when running everything locally, calling the exact same database with that very connection string everything works as it should; I can add records to that production Azure database just fine, but as soon as I try doing the same from my client app from production I get that dreaded error mentioned above.
Can anyone tell me what might be happening? I've been over and over this and it's driving me mad. I've even gone as far as changing the connection string to be Server=... I've made sure to append the # to the user_id. I believe I've tried just about everything I could find that wasn't 8 years old, including searching similar issues here... nothing seems to be quite like my issue exactly.
If you need more information let me know and I'll update my question.
Thanks!
EDIT: Adding this to show I've already added all of my output IPs from my api app service to my Sql server firewall. Can someone tell me if all my settings look good?

Scaffold-DbContext Error "Login failed for user MicrosoftAccount\my_email#gmail.com"

Trying to execute this command in Visual Studio Package Manager Console:
Scaffold-DbContext "Server=my_server\SQLEXPRESS;Database=FoodStore;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
but I'm getting this error:
Cannot open database "FoodStore" requested by the login. The login
failed. Login failed for user 'MicrosoftAccount\my_email#gmail.com'.
I've tried creating a login in Security for 'MicrosoftAccount\my_email#gmail.com' as db_owner in Microsoft SQL Management Service Studio, as well as signing in with local accounts instead, but I'm still getting an error in Visual Studio when running Scaffold-DbContext.
I was also facing the same error but Ifound the solution. In scaffolding string I am using the server name "LAPTOP-82GAEQ6T\SQLEXPRESS" but in SQL server I am using only "LAPTOP-82GAEQ6T". That's the same error I was facing, please check your server connection name on both sides, on the server side and your connection string. Best of luck.
I encountered the same issue as you have mentioned i.e.
Cannot open database "dbxxxxx" requested by the login. The login failed.
Login failed for user 'xxxxx\xxx'.
And after working around with it, I found that I had to carefully check the value of
server attribute.
"Server=.\SQLEXPRESS;Database=FoodStore;Trusted_Connection=True;" also works well.

Error: 18456, Severity: 14, State: 38 Reason: Failed to open the explicitly specified database 'ReportServer'. [CLIENT: <local machine>]

I'm facing a situation which every 10 seconds an error log is recorded with the following msg:
2018-07-25 09:07:09.59 Logon Error: 18456, Severity: 14, State: 38.
2018-07-25 09:07:09.59 Logon Login failed for user 'svc_sql'. Reason: Failed to open the explicitly specified database 'ReportServer'. [CLIENT: <local machine>]
In my instance I don't have a 'ReportServer' database. I know that in the past the server was migrated to a new machine and I reckon the 'ReportServer' database was created with a new name in the new server. I really don't know how the migration was done.
I've activated the SQL_Profiler with all audit options and I could see that this user also executes a procedure sometimes.
I've checked the default database for this user and it's Master.
Any ideas how can I fix this issue? My error log is flooding with this message.
Thanks a lot.
Rod
I've checked the default database for this user and it's Master.
The error doesn't tell you about default database but about explicitly specified database, that is different, it's the database that is mentioned in connection string under Initial Catalog or Database.
Do you see what application tries to open this database? The problem is in that application, it uses old connection string. If it's SSMS, it's simple, it's in the Options of connection dialog, but if it's another application, the connection string can be written in the ini file or hardcoded.
I don't know if I try to run DBCC CHECKDB master will solve this.
Of course it cannot solve this. This has nothing to do with database integrity. It's your client that uses wrong connection string.
Any ideas how can I fix this issue? My error log is flooding with this
message.
If you just want to save your errorlog from these messages just turn off failed logins audit:
Or you should find this application by its name or host or client address.
Or you can temporarily disable this login and see who will call you saying he cannot login anymore, or, if it's your local machine, some of your applications will fail, this way you'll find it.
I had the same error and doing the following resolved the error for me:
From within the SQL Server Management Studio
Security
Logins
Right Click the user ID that was failing login
Server Roles
Make sure all the checkboxes are checked. Right clicked Security and refresh.

sql server 2012 copy database failed between two instances on the same host

I am learning the sql server 2012 and got stuck when using the copy datase, trying to figure out why.
I created two instances on the same host, using administrator, windows authentication.
(the default instance:iZp0w14yqtvxcmZ, the second instance: iZp0w14yqtvxcmZ\instance2, try to copy database from the default one to the second one)
It failed at the last step: execute sql server agent job.
here is the error log from windows event viewer:
Message: Failed to connect to server iZp0w14yqtvxcmZ.
StackTrace: at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.OpenConnection(Server& server, ServerProperty serverProp)
InnerException-->Login failed for user 'NT Service\SQLAgent$INSTANCE2'.
Then I tried to add the login 'NT Service\SQLAgent$INSTANCE2' in the default instance. Then tried again and got another error:
Event Name: OnError
Message: An error occurred while transferring data. See the inner exception for details.
StackTrace: at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferExtraObjectsViaSmoTransfer()
InnerException-->Windows NT user or group 'iZp0wd5ebkvswaZ\Administrator' not found. Check the name again.
But the Adminitrator does exist in the computer management -> local user and groups -> group, so I don't know what to do now. NEED HELP !!!
Thanks a lot!
after two-day's struggling, I figured it out. The sql server agent service should use a domain-based account for a multi-server environment. Also that account should be able to log in and perform the job.
I solved the issue changing the login method to system local account.
Two instances must have the same password and open, then in this case:
insert into [EI7-PC\SQLEXPRESS2].[MYCOMPANY].[dbo].[inventory] SELECT *
FROM [EI7-PC\SQLEXPRESS1].[MYCOMPANY].[dbo].[inventory] where itemno='10-0001'
The reason for the same password is unknown, this is per my experience. With two different password you may get an error about 'sa' failed to login.

Microsoft Azure: There was an error while creating data connection 'SQL data connection'. Deployment to resource group failed

I am trying to create an Android Mobile app via the Azure app service and while doing so, I am trying to create a database, but I am getting the error 'there was an error while creating data connection 'SQL data connection'. Deployment to resource group failed'. Please help as soon as possible.
$
This error is due to server limit exceeding the quote associated with your account. Under all resources, check if there's a new SQL server created with a random name- you will need to delete that. Attempt to create again.
(just done- it worked!)
I've faced the exact issue.
First time it failed giving the error - Data Connection Creation Error..!
When Configuring for the first time it didn't work for me.
i.e.,
Creating a Database
Creating a New Server
Entering Server Admin Login
Entering Server Admin Password
I've noted down all the above information.
Tried Second time setting up the Connection String with the above details IT WORKED.
Hope this information helps.