1. 程式人生 > 實用技巧 >EF Core Migration 報錯:An error occurred using the connection to database '' on server '10.28.253.2'

EF Core Migration 報錯:An error occurred using the connection to database '' on server '10.28.253.2'

EF Core Migration update-database的時候 An error occurred using the connection to database '' on server '10.28.253.2'

問題:在做EF Core Migration的時候,Update-dataBase指令總是報錯報錯內容為“An error occurred using the connection to database '' on server '10.28.253.2'”

在做資料遷移的時候,按照常規操作

  • Add-Migration init(執行此命令專案生成一個目錄(Migration))
  • Update-Database init

使用的資料庫連線字串之前是可以查詢成功的,字串內容如下

"ConnectionStrings": {
    "Default": "Data Source = 10.28.253.2;Initial Catalog = SignalR;User Id = sa;Password =Ecsgui123;"

可是今天拷貝過來之後,死活執行報錯,報錯內容如下圖所示:

自己找錯誤的時候,還找錯了錯誤語句,用了綠色圖示中的“Access denied for user”,這句是執行錯誤最後一行的提示資訊,出現了一個程式中都不成出現的“10.28.160.250”這個地址,找的一頭亂碼

仔細檢視錯誤碼,發現一開始的報錯內容IP是正確的,但是提示連線不上,紅色框框內容,於是乎將連線字串中增加了“Integrated Security=False;”內容,問題到此解決。

"ConnectionStrings":
"Default": "Data Source = 10.28.253.2;Initial Catalog = SignalR;User Id = sa;Integrated Security=False;Password =Ecsgui123;"