我正在將ASP.NET webforms網站遷移到新服務器。在舊服務器上,我的數據庫位於網站根目錄的App_Data文件夾中。在我的新服務器上,我將數據庫放在根目錄之外的其他文件夾中,並且一切正常。配置文件命令生成App-Data文件夾和ASPNETDB.MDF
但發生了一些奇怪的事情。當我訪問網站並衝浪時,突然在我的站點的根文件夾中創建了一個App_Data文件夾,其中包含一個名爲ASPNETDB.MDF的數據庫。我可以刪除它,但過一段時間後會再次出現。
我做了一些測試和嘗試,我發現了正在創建的數據庫,當我運行這段代碼:
TestLabel.Text = Profile.MyProfileParameter.ToString();
所以我想它一定是被稱爲導致它的配置文件。 在我的web.config我有以下幾點:(有點降低,我有多個外形參數)
更高在我的web.config甲比特i有一個指向數據庫我的根以外的ConnectionString文件夾:
<connectionStrings>
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
有沒有人知道爲什麼調用配置文件會生成一個數據庫? 這不是一個真正的展示塞,但我想知道爲什麼會發生這種情況。
一些額外的信息:
- 我的老服務器的Windows Server 2003
- 我的新服務器的Windows Server 2008 R2
- 我的應用程序在ASP.NET 3.5
運行SOLUTION:
顯然有sti我會學到很多關於web.config的知識。
除了web.config,還有一個machine.config,web.config繼承自它。 在部分<profile>
這臺機器的配置有此設置:
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
此設置可以在web.config
首先被覆蓋(我不認爲這是真的需要)我刪除了localSqlServer從連接字符串中加入一個明確的命令,我<connectionStrings>
:
<connectionStrings>
<!-- clear command removes localSqlServer from machine.config -->
<clear />
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
如果我跑我的網站現在你會得到一個錯誤說連接名「LocalSqlServer」沒有被發現。
所以我增加了一個新的提供商,爲<profile>
部分,並將其指向我的ConnectionString
<profile enabled="true">
<providers>
<!-- clear command removes localSqlServer from machine.config -->
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="ConnectionString" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
現在這一切工作呈現出藍色的罰款,沒有更多的數據庫。
謝謝ijaz給的指示,獎金是你的!
你的目標是什麼版本Asp.Net,如4.0或4.5,新舊服務器的操作系統版本。 – ijaz