【问题标题】:"The connection string specifies a local Sql Server Express instance", Except it Doesn't“连接字符串指定了一个本地 Sql Server Express 实例”,但它没有
【发布时间】:2011-12-21 21:59:46
【问题描述】:

我正在尝试将 asp.net 应用程序部署到使用 SQL Server 实例作为 ApplicationServices 成员资格数据库的服务器。

问题是,我收到一个错误提示

连接字符串指定一个本地 Sql Server Express 实例 使用应用程序 App_Data 目录中的数据库位置

当我最初尝试将 aspnetdb.mdf 本身与应用程序一起部署时,我遇到了这个错误。

当我放弃该计划并决定执行web.config 转换以便在调试中使用 Express 数据库时遇到此错误,但在发布时连接字符串转到 SQL Server。

当我出于好奇决定从代码中删除对 express 数据库的所有引用时,我再次遇到此错误,因此不可能有任何方法来查找 Express 数据库。没有运气。

有人对此有任何想法吗?我每次都在 IIS 中删除并重新安装了该网站,并注意到没有部署 App_Data 并且没有提及 web.config 中的 .mdf 文件 - 无济于事。它仍然认为有一个连接字符串告诉它寻找 SQL Server Express 数据库:/

编辑:这是我正在使用的连接字符串。我认为这很标准,但我可能总是错的。

Data source=HERP;Initial Catalog=DERP;Integrated Security=True

【问题讨论】:

  • 你能发布连接字符串吗?
  • 你能告诉我们你的 web.config 吗?你可以 xxxx 出任何敏感的东西。
  • 您可能应该添加来自 web.config 的任何连接字符串(搜索 data source=)以及生成错误的代码部分
  • 错误信息的其余部分是什么?
  • @Andomar - 这是当前 web.config 中唯一的连接字符串。我把另一个拿出来试图消除错误(它不起作用)

标签: asp.net sql-server deployment


【解决方案1】:

该错误是否是指machine.config 文件中的默认连接字符串(LocalSqlServer 之一)?这可能会发生,考虑到default membership provider uses this connection string:

以下默认成员资格元素在 Machine.config 文件 [...]:

<membership>
<providers>
<add name="AspNetSqlMembershipProvider" [...]
connectionStringName="LocalSqlServer" [...]

【讨论】:

  • 非常感谢 - 这显然是它正在寻找的连接字符串。我可以通过简单地将 machine.config 连接字符串指定为我想要的 SQL Server 连接字符串(上面提到)来使用 hacky 立即修复,但是您知道修复此问题的标准/非 hacky 方法,因此它使用我的连接字符串而不是 LocalSqlServer 之一?再次感谢,这是一个巨大的帮助。
  • 您可以在自己的web.config 中覆盖machine.config 中的任何内容。见msdn.microsoft.com/en-us/library/…The easiest way to have your application automatically take advantage of your newly created SQL database is to just replace the connection string value of this LocalSqlServer setting in your app's local web.config.
  • 这也帮助我找出了我的问题.. 在一台机器上运行良好,但在另一台机器上运行良好,尽管它们具有相同的连接字符串。原来 web.config 缺少 节点。
【解决方案2】:

别忘了先清除connectionStrings:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多