此文章為本系列的第四篇,主要用來說明 WebMatrix 開發工具的檔案管理以及資料庫管理等功能,這次我們改用另一套微軟精心打造的開源碼內容管理系統 Orchard CMS 來做示範操作,整個精簡後的操作介面一樣的簡單到恰到好處。
透過 WebMatrix 來安裝 Orchard CMS 可以說再方便不過了,如果讀者有看完前幾篇文章的話,想必一定知道如何透過 Web 組件庫 快速安裝好一個站台。安裝好 Orchard CMS 進 WebMatrix 之後由於資料庫尚未被建立,因此必須先將網站執行起來並執行基本的設定程序才行。

由於 Orchard CMS 是一套網站內容管理系統,因此在安裝的時候必須先設定好網站的名稱與預設管理者的帳號、密碼(請注意:密碼必須輸入至少 7 個字元):

Orchard CMS 支援兩種資料庫後端,一種是精簡版的 SQL Server ( SQL Server Compact ),另一種是 SQL Server Express 版,為了完成本次教學,我們先使用 SQL Server Compact 進行安裝,然後按下 Finish Setup 即可完成設定:

設定完成的畫面如下圖示:

這時我們就可以切回 WebMatrix 的視窗畫面。
介紹「資料庫」工作區
我們切換到「檔案」工作區,在這裡你可以針對檔案與目錄進行基本的管理,還能與檔案總管進行互動,例如從檔案總管複製檔案,可以到「檔案」工作區的導覽區做貼上等動作。另外,你還能直接從 WebMatrix 中的任意一個目錄開啟檔案總管,如下圖示:

除此之外 WebMatrix 裡面還內建了一個基本的文字編輯器,雖然在 v1 的版本連 Intellisense 的功能都沒有,不過在日後的版本應該會補上這個功能,至於其他編輯功能都跟一般的文字編輯器差不多:

在檔案工作區的 Ribbon 功能裡,比較特別的應該是 Visual Studio 這個功能,因為 WebMatrix 比較被定位在簡易型的免費開發工具,為了填補在進階開發與除錯的不足之處,它也整合了 Visual Studio 進來,只要你的本機有安裝 Visual Studio 2010 就會自動被開啟:

但是如果你連 Visual Studio 2010 都沒有怎麼辦呢?沒關係,WebMatrix 會將 Web PI 叫起來並詢問你是否要自動安裝免費版的 Visual Web Developer Express 2010 SP1 開發工具!

介紹「資料庫」工作區
在「資料庫」工作區裡,你可以瀏覽與這個站台相關的資料庫,不管是 MySQL, SQL Server 或者是 SQL Server Compact 都能夠透過 WebMatrix 對資料庫裡的進行資料的瀏覽與編輯 (新增、刪除、修改),使用者完全不需要學習各家資料庫系統的管理工具,透過 WebMatrix 就能做完所有事情,而且不同資料庫之間的管理與使用方式完全一模一樣。


除了瀏覽資料外,你還能新增資料表、設計資料表 (定義)、新增索引、新增資料表關聯 (關係)、…等等:


然而,如果你用的資料庫是 SQL Server Compact 的話,由於是精簡版的關係僅支援資料表功能,若要使用進階的 檢視 (View) 與 預存程序 (Stored Procedure) 功能,就必須升級到 SQL Server Express 以上,因此 WebMatrix 甚至還內建了「移轉」功能,能夠將你的 SQL Server Compact 資料庫自動轉移到本機或者是遠端的 SQL Server 裡:

如果你尚未安裝 SQL Server Express 的話,按下上圖的「安裝」按鈕也會自動安裝,或是在移轉的設定畫面中也能直接安裝 SQL Server Express,當然,這整個安裝過程非常簡單,跟你自己安裝 SQL Server Express 比起來還要簡單數倍:



由於下載 SQL Server Express 2008 R2 需要 83.59MB,下載與安裝可能需要費些時間完成:


轉移資料庫到新的平台後,我們重新執行一次「移轉」功能,移轉時要設定目的資料庫的名稱,過程中他會自動幫你建立一個新的資料庫:


轉換過後你會發現兩個地方不太一樣了:
- 資料庫圖示變了
- 資料庫功能多了「檢視」與「預存程序」

所以如果你今天使用的資料庫系統有本身就有支援 檢視 (View) 與 預存程序 (Stored Procedure) 的話,也能在 WebMatrix 中直接進行編修設計,真的是在一個工具裡面做完所有 80% 日常開發維護中最常做的工作:



主要功能已經講解的差不多了,不過如果你想在同一個站台裡管理多個資料庫,也可以透過「新增連線」的方式加進 WebMatrix 之中一起管理:

相關連結