【问题标题】:Azure Cloud Service App trying to connect to (localdb) instead of Azure SQLAzure 云服务应用程序尝试连接到 (localdb) 而不是 Azure SQL
【发布时间】:2013-09-12 11:16:36
【问题描述】:

我有一个新应用程序,我正尝试将其部署到 Azure 云服务。使用 VisualStudio 2012、Entity Framework - Code First 和 SQL Server Management Studio 在本地开发。

我有一个 Azure 云服务项目、一个 Web 角色项目、一个服务层类 (C#) 库和一个数据对象类库。

这些都在我的本地机器上完美地协同工作。 Web 调用服务,服务调用上下文,上下文返回(或修改)对象。耶!

然后我发布了网络应用程序。使用此语句添加了 web.release.config 转换...

<connectionStrings>
    <add name="DefaultConnection"
    connectionString="Server=tcp:xmeg1j7x57.database.windows.net,1433;Database=RS.Core.Objects.RSData;User ID=****@xmeg1h7x57;Password=**********;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

并没有快乐。它似乎仍在尝试调用我的 (localdb)。

所以我在本地运行它(已将 web.config 更改为具有 azure 生产字符串),然后在断点处查看...

WebConfigurationManager.AppSettings["DefaultConnection"]

期待一个字符串。发现了一个数组。第二个值来自 web.config,但第一个值是自动生成的对 (localdb) 的引用。我如何摆脱这个参考?显然我遗漏了一些东西,但数小时的研究证明我的 Google-Fu 很弱。

【问题讨论】:

    标签: c# visual-studio-2012 azure azure-sql-database azure-web-roles


    【解决方案1】:

    过去我要检查两件事是否导致了这个问题:

    1. 在创建 MembershipProvider 之前,我调用了一些 System.Security 方法(特别是 User.IsInRole())。出于某种原因,这试图检查 localdb 实例以获取用户信息。一旦 MembershipProvider 运行,我就没有这个问题。由于时间限制,我围绕这个错误进行了编码。
    2. 将连接字符串从“DefaultConnection”重命名为其他名称,可能是“AzureDbConnection”,并在适当的地方更改所有引用。

    您可能还会发现在整个项目中搜索“DefaultConnection”并查看它是否被动态设置以及清除任何 app.configs 的连接字符串信息很有用。

    【讨论】:

    • 谢谢,我一定会尝试第二个。我目前没有实施任何安全措施 - 广泛开放的访问。
    【解决方案2】:

    尝试在“添加”之前添加&lt;/clear&gt;

    <connectionStrings>
        </clear>
        <add name="DefaultConnection"
        connectionString="Server=tcp:xmeg1h7x57.database.windows.net,1433;Database=RS.Core.Objects.RoomScopeData;User ID=RSAdmin@xmeg1h7x57;Password=**********;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
    </connectionStrings>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      相关资源
      最近更新 更多