0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeORMでSQL Serverにログインしようとしたら「Login failed for user 'sa'.」というエラーが出る

Last updated at Posted at 2025-03-19

TypeORMを使用してDockerコンテナ内のSQL Serverに接続しようとした際、「Login failed for user 'sa'」というエラーが発生しました。このエラーの原因と解決方法について説明します。

エラー内容

ユーザー名とパスワードが正しいにも関わらず、接続試行時に以下のようなエラーが出ました:

Failed to start the server: ConnectionError: Login failed for user 'sa'.

原因

エラーの原因は、SQL Server内にデータベースが存在しないことでした。SQL Serverは指定されたデータベースが存在しないと、ログインすらできないようです。(.NET EntityFrameworkはデータベースがなくてもマイグレーションでデータベースを作成できたので、その違いに戸惑いました。)

解決方法

  1. SSMS, Azure Data Studioなどでデータベースを作成

    SQL Serverに接続後、CREATE DATABASEコマンドなどを使用して、接続したいデータベースを作成します。

  2. データベース作成後に再実行

    データベースを作成した後、再度TypeORMの接続を試みてください。これで「Login failed for user 'sa'」エラーは解消され、ログインできるようになります。

最後に

Login failed for user 'sa'というエラーが出た場合、まずはデータベースが存在するかを確認してください。データベースが存在しないとログインできません。SSMSや他のSQLクライアントを使って、データベースを作成し、再度接続を試みることで、問題は解決できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?