簡體   English   中英

SQL配置文件給服務器找不到異常

[英]SQL Profile giving server not found exception

我正在嘗試在程序中使用個人檔案。 從命令行使用aspnet_regsql.exe創建必要的表可以正常工作。 但是,拋出System.Web.HttpException異常,表示我嘗試運行該應用程序時無法連接到數據庫。 這很奇怪,因為我已連接到VS 2013中服務器瀏覽器上的數據庫。這是應用程序網站上的錯誤消息。

建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱正確,並且已將SQL Server配置為允許遠程連接。 (提供者:SQL網絡接口,錯誤:26-指定服務器/實例時出錯)

這是我的Web配置文件中的相關代碼。

<profile defaultProvider="SqlProvider" inherits="[Namespace].AccountProfile">
    <providers>
        <clear/>
        <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="[stringname]"/>
    </providers>
    <properties>
        <add name="Rows" type="System.String"/>
        <add name="Area" type="System.String"/>
    </properties>
</profile>

這是我的應用程序中引發異常的代碼

AccountProfile.cs

public class AccountProfile : ProfileBase
{
      static public AccountProfile CurrentUser
      {
           get { return (AccountProfile)(ProfileBase.Create(Membership.GetUser().UserName)); }
      }

    ....
}

原來,代碼的Membership.GetUser()部分仍在嘗試使用machine.config文件中找到的LocalSqlServer連接字符串,而不是我在web.config中提供的數據庫連接字符串。 在我的connectionString配置中添加<clear />幫助我弄清楚了這一點。

<connectionStrings>
<clear />
    <add name="..." connectionString="Data Source=...;Initial Catalog=...;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM