はじめに
DockerでMicrosoft SQL Server - Ubuntu based images
のコンテナを立てた後、Entity Framework Core
を利用してマイグレーションを実行しようとしました。(エンティティ・コンテキスト定義、データベース接続文字列設定&アプリに紐づけ済)
mcr.microsoft.com
$ dotnet ef migrations add Initial
$ dotnet ef database update
すると以下のようなエラーが出力されてしまいました。
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)
この解決方法を見つけたので書き残しておこうと思います。
解決方法
appsettings.json
を用いて、ConnectionStrings
を記述していましたが、その際Encrypt=false
を追加すれば動作しました。
"ConnectionStrings": { "MyContext": "Server=localhost;Database=YOURDATABASE;user=sa;password=YOURPASSWORD;Trusted_Connection=false;" }
↓
"ConnectionStrings": { "MyContext": "Server=localhost;Database=YOURDATABASE;user=sa;password=YOURPASSWORD;Trusted_Connection=false;Encrypt=false" }
少なくとも開発用 or localhost
であればこれでOKです。またTrustServerCertificate=True
でも動作するかもとのことでした。