Login Failed when trying to use SQL database to store wpf data

uzair akhalwaya 1 Reputation point
2022-05-01T12:42:28.7+00:00

System.Data.SqlClient.SqlException: 'Cannot open database "StockSystemdb." requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\MyEmail'.'

Any fix?

Azure SQL Database
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,800 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,158 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,181 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 113.7K Reputation points MVP
    2022-05-01T15:23:39.853+00:00

    Well, you would need to add MicrosoftAccount\MyEmail as a user in the database StockSytsemDb.

    It could have helped if you had included what troubleshooting you have performed, and some information why you don't expect to get this error.

    0 comments No comments

  2. AmeliaGu-MSFT 13,986 Reputation points Microsoft Vendor
    2022-05-02T06:12:51.637+00:00

    Hi uzairakhalwaya-2700,

    Welcome to Microsoft Q&A.
    Could you please try to use user 'MicrosoftAccount\MyEmail' to connect to SQL Server database and see if there are any detailed error message?
    And what the connection string are you using?
    Please make sure user 'MicrosoftAccount\MyEmail' exists under database->security->users.

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.