简体   繁体   中英

Azure Cloud Service App trying to connect to (localdb) instead of Azure SQL

I have a new App that I am trying to deploy to Azure Cloud Services. Developed locally using VisualStudio 2012, Entity Framework - Code First, and SQL Server Management Studio.

I have an Azure Cloud Services Project, a Web Role Project, a service layer class (C#) library, and a data objects class library.

These all work together beautifully on my local machine. Web calls service, service calls context, context returns (or modifies) objects. Yay!

I then published the web app. Added a web.release.config transform with this statement...

<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>

and no joy. It still seemed to be trying to call my (localdb).

So I ran it locally (having changed the web.config to have the azure production string) and, at a breakpoint, looked at...

WebConfigurationManager.AppSettings["DefaultConnection"]

expecting a string. Discovered an array. Second value was from the web.config, but the first was an auto-generated reference to (localdb). How do I get rid of this reference? Obviously I'm missing something, but hours of research have proved my Google-Fu to be weak.

Two things to check for that have caused this issue for me in the past:

  1. I was calling some of the System.Security methods (specifically, User.IsInRole()) prior to the MembershipProvider being created. For some reason, this tried to check the localdb instance for user information. Once the MembershipProvider was running, I didn't have this issue. I coded around this bug due to time restrictions.
  2. Rename your connection string from "DefaultConnection" to something else, maybe "AzureDbConnection", and change all the references where appropriate.

You might also find it useful to search the entire project for "DefaultConnection" and see if it is being dynamically set, as well as clearing any app.configs of connection string information.

Try adding a </clear> before the "add"?

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM