0%

研究 ABP Framework 時遇到的問題

Setup Your Development Environment

一開始跟這官方教學先設置一些環境

https://docs.abp.io/en/abp/latest/Getting-Started-Setup-Environment?UI=MVC&DB=EF&Tiered=No

截圖 2021-03-26 下午2.57.06

在安裝 abp cli 時發現即使安裝完在終端機輸入 abp new ... 會出現 command not found

問題應該是沒有將 abp 的路徑 export 到系統 path 中,照著這個連結做就可以使用 abp cli 了

Create a New Project

1
abp new Acme.BookStore

這邊沒什麼問題,使用這條指令會自動建立一個 abp 範例專案

Running the solution

準備資料庫

這邊一開始要在資料庫建立一個 db 並命名為 BookStore

再來要使用 abp 提供的 db migration 工具,這邊也遇到一個問題,由於我是在 m1 mac 使用,使用的環境是

  • IDE: Visual Studio for Mac
  • DataBase: docker 內裝 azure-sql-edge (由於 m1 mac 似乎沒辦法裝 mssql server 的 image,azure-sql-edge 是一個支援 arm 的 image,功能與 mssql server 相同但有些限制,但我沒有深入去研究有哪些限制,不過目前來看跑起來跟一班的 mssql server 差不多)

在官方文件中 connection string 的設定方法是寫這樣

1
2
3
"ConnectionStrings": {
"Default": "Server=localhost;Database=BookStore;Trusted_Connection=True"
}

由於我的 db 有設帳號密碼所以我的版本是這樣

1
2
3
"ConnectionStrings": {
"Default": "Server=localhost,1433; Database=BoilerplateDb; User=sa; Password=<YourStrong@Passw0rd>"
},

這邊的 Trusted_Connection=True 和 localhost,1433 是我後來修改的

Trusted_Connection=True 如果有填寫的話會造成下面這個錯誤

1
Cannot authenticate using Kerberos. Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication. ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - An unsupported mechanism was requested (unknown mech-code 0 for mech unknown).

要解決的話就是把 Trusted_Connection=True 拿掉即可 參考連結

Localhost,1433 如果不像這樣指定 port 會連不到,所以只好在後面指定

上面的 connection string 都設定完後就可以運行 DbMigration 這個專案,成功的話應該會看到下面的內容

1
2
3
4
5
6
7
den19980107@den19980107s-MacBook-Pro Acme.BookStore.DbMigrator % dotnet run 
[15:22:05 INF] Started database migrations...
[15:22:05 INF] Migrating schema for host database...
[15:22:07 INF] Executing host database seed...
[15:22:10 INF] Successfully completed host database migrations.
[15:22:10 INF] Successfully completed all database migrations.
[15:22:10 INF] You can safely end this process...

運行 app

.Web 這個專案下面跑 dotnet run 即可將 app 跑起來,注意的是 .Web 也有一個自己的 connection string,要記得改成跟上面一樣的

這個步驟沒有遇到什麼問題,很正常的跑起來了

截圖 2021-03-26 下午3.26.10