2011-01-10 73 views
4

如何更改ASP.NET配置工具連接字符串名稱? (ASP.NET配置工具將使用哪個連接字符串) 我正在學習ASP.NET和無處不在以及我正在閱讀的書中,現在讀取了名爲LocalSqlServer的連接字符串。如何更改ASP.NET配置工具連接字符串

我想用我的本地sql server數據庫而不是sql express來存儲角色,成員和其他數據。

我已經使用aspnet_regsql.exe在我的數據庫中創建所需的數據結構。之後,我改變了我的web.config看起來像:

<connectionStrings> <remove name="LocalSqlServer"/> <add name="LocalSqlServer" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

但是當我運行ASP.NET配置工具,它說: 「連接名稱‘ApplicationServices’在應用程序的配置沒有被發現或連接字符串是空的。「

ASP.NET配置工具使用名爲ApplicationServices而不是LocalSqlServer的連接字符串。

原因,我必須修改web.config中: <connectionStrings> <add name="ApplicationServices" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

,一切工作正常。

我想知道爲什麼我的網站使用連接字符串命名爲:ApplicationServices和所有書籍和在線文檔使用LocalSqlServer?以及如何將其更改爲LocalSqlServer?

我: 的Windows 7 的Sql Server 2008 R2的 Visual Studio 2010的溢價 項目類型網站

+0

感謝,你解決了我的問題 – 2016-03-29 10:41:49

回答

15

無意中我發現我的問題的答案尋找web.config文件時。

如果您覆蓋web.config文件中的默認machine.config配置設置,則可以更改ASP.NET配置工具的連接字符串名稱。

我從book-s代碼歸檔中獲得了我的web.config文件,這是問題所在。

在web.config中,你可以重載將使用哪個連接字符串名稱:membership,profile和roleManager。

重寫成員使用:
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/"/>
</providers>
</membership>

其中的connectionStringName是將被用於存儲數據成員的連接字符串的名稱。

別人:

<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="LocalSqlServer"
applicationName="/"/>
</providers>
</profile>

<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="LocalSqlServer" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>