使用LocalDB部署Asp.Net MVC網站時遇到的問題

來源:互聯網
上載者:User

標籤:找不到   許可權   ble   environ   nec   conf   .com   相關   伺服器   

首先一句話介紹LocalDB。LocalDB是SQLServer的檔案資料庫,類似於SQLite。它擁有SQLServer的絕大部分功能,簡單易用。但部署LocalDB到生產系統是不推薦的。本文部署是一個內部微系統,資料庫僅僅只用來做一個最基本的使用者認證而不做其他。基於此,決定直接試用LocalDB部署。

之前對LocalDB並不瞭解,雖然說其類似於SQLite,但SQLite是 一個生產用資料庫,而LocalDB更像是基於體驗的。系統經過基本調試、驗證後,直接試用Visual Studio發布到遠端Windows 2008 SP1系統。開啟網站,網站報錯。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. 
Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local
Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

經過搜尋,在StackOverflow以及MSDN上都有相關的描述。主要是LocalDB與Full IIS應用不相容,需要按照某一個補丁,進行額外設定。我不確定最新的IIS是否已經相容,至少在Windows 2008 Serve R2上的IIS版本不相容。在Using LocalDB with Full IIS, Part 1: User Profile[1]一問中有更加詳細的描述。按照其Part1的設定,網站依然沒有跑起來。在Windows 7 SP1 causes IntelliTrace Collection to fail on IIS[2]提到了不相容的補丁資訊,以及如何解決。

 

著急之下,直接在伺服器上安裝SQLServer Express。如果LocalDB不建議部署,準備隨即轉移到Express。在一些參考上,又提到SQL Server Runtime,可能是沒有安裝Express的原因。安裝完SQLServer Express,網站依然無法正常工作。在下載Express時,看到還有一個下載選項為CHS\x64\SqlLocalDB.msi 。可能此程式才是LocalDB的Runtime。遂卸載 SQLServer Express,安裝SQlLocalDB。再次運行網站,錯誤資訊變為如下:

//大概是這個意思找不到SQLServer進程無法啟動執行個體

看來LocalDB還需要與SqlServer Express協同工作。安裝好之後,再次啟動網站,錯誤依舊。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance
name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. 在 LocalDB
執行個體啟動期間出錯: 無法啟動 SQL Server 進程。)

在[1][2]中提到還需要設定IIS的應程式池資訊,之前沒有改變是因為我以試用Administrator身份運行此程式。按照[1][2]的方法,增加應用程式集區設定。

<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0">    <processModel identityType="SpecificUser" userName="administrator" password="**********" loadUserProfile="true" setProfileEnvironment="true" /></add>

本Web App主要進行伺服器管理,與作業系統(Win32 Api)互動較多,部分Api需要很高許可權。在以上設定中增加了loadUserProfile="true" setProfileEnvironment="true" ,賦予程式池讀取使用者配置、環境參數的能力。重新啟動應用程式集區,App正常運行。

回過頭來看,如果要部署LocalDB到IIS 可以參考Deployment of SQL Express LocalDB on IIS[3]。就此次實踐來說,大概要經過這麼幾部:

  1. 環境為Widnows 2008 R2
  2. 需要安裝SQL Server Express,安裝SqlLocalDB.
  3. 需要配置C:\Windows\System32\inetsrv\config\applicationHost.cof,賦予應用程式集區讀取使用者資料、環境資料的資訊。

 

 

參考:

[1]Using LocalDB with Full IIS, Part 1: User Profile, https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/

[2]Windows 7 SP1 causes IntelliTrace Collection to fail on IIS, https://support.microsoft.com/zh-cn/kb/2547655

[3]Deployment of SQL Express LocalDB on IIS, https://blogs.msdn.microsoft.com/gaurav/2013/12/21/deployment-of-sql-express-localdb-on-iis/

[3]Stack Overflow上的提問, http://stackoverflow.com/questions/26248293/sql-network-interfaces-error-50-local-database-runtime-error-occurred-canno

使用LocalDB部署Asp.Net MVC網站時遇到的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.