在 Visual Studio 中啟動 Azure 專案調試時,輸出視窗顯示:
Windows Azure Tools: Failed to initialize Windows Azure storage emulator. Unable to start Development Storage. Failed to start Storage Emulator: the SQL Server instance 'localhost\SQLExpress' could not be found.
這表示本地開發儲存模擬器找不到預期的 SQL Server Express 執行個體。
SQLServer2019-SSEI-Expr.exe(或更新版本)安裝,執行個體名稱保持預設 SQLEXPRESS。
dsinit /sqlinstance:.\SQLEXPRESS /forcecreateDevelopmentStorageDb 資料庫並設定連線字串。
services.msc → 找 "Azure Storage Emulator" → 啟動類型設為「自動」,並啟動服務。
| 錯誤訊息 | 可能原因 | 解決方向 |
|---|---|---|
| Cannot connect to SQL Server | SQL Express 服務未啟動 / 防火牆阻擋 1433 | 啟動 SQL Server (SQLEXPRESS) 服務;防火牆開放 TCP 1433 |
| Login failed for user | Windows 驗證失敗 / 執行個體名稱錯誤 | 確認實例名 .\SQLEXPRESS;嘗試 dsinit /sqlinstance:localhost\SQLEXPRESS |
| Database 'DevelopmentStorageDb' already exists | 殘留資料庫阻礙重建 | dsinit /forcecreate 強制重建;或手動 Drop 資料庫再執行 |
Visual Studio 2017+ 預設改用 SQL Server LocalDB(輕量級、按需啟動)。若偏好 LocalDB,執行:
dsinit /sqlinstance:(localdb)\MSSQLLocalDB /forcecreate
LocalDB 無需常駐服務,適合開發機資源有限的情境。
@echo off
rem 檢查 SQL Express 服務
sc query "MSSQL$SQLEXPRESS"
rem 初始化 Storage Emulator
"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\dsinit.exe" /sqlinstance:.\SQLEXPRESS /forcecreate
pause
完成上述步驟後,重新啟動 Visual Studio 並啟動調試,Storage Emulator 應能正常初始化,專案即可順利連接本地 Blob/Queue/Table 服務進行開發測試。