【问题标题】:SQL Profile giving server not found exceptionSQL 配置文件给服务器未找到异常
【发布时间】:2014-06-30 20:50:22
【问题描述】:

我正在尝试在我的程序中使用配置文件。从命令行使用 aspnet_regsql.exe 创建必要的表工作正常。但是,当我尝试运行应用程序时,会引发 System.Web.HttpException 异常,说它无法连接到数据库。这很奇怪,因为我在 VS 2013 中连接到服务器资源管理器上的数据库。这是我的应用程序网站上的错误消息。

发生网络相关或特定于实例的错误,同时 建立与 SQL Server 的连接。找不到服务器或 无法访问。验证实例名称是否正确,并且 SQL Server 配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 定位服务器/实例时出错 指定)

这是我的网络配置文件中的相关代码。

<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)); }
      }

    ....
}

【问题讨论】:

    标签: c# asp.net sql-server visual-studio profile


    【解决方案1】:

    原来代码的 Membership.GetUser() 部分仍在尝试使用在 machine.config 文件中找到的 LocalSqlServer 连接字符串,而不是我在 web.config 中提供的数据库连接字符串。在我的 connectionString 配置中添加 &lt;clear /&gt; 帮助我解决了这个问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2012-08-06
      • 2023-02-23
      相关资源
      最近更新 更多