Azure Web Sites connection string for EF not being picked up
Asked Answered
P

1

11

I am deploying an ASP.NET web app to Azure Web Sites.

The site uses Entity Framework, and when I include the following in Web.config it runs fine:

<connectionStrings>
  <add name="DataContext" connectionString="metadata=res://*/Models.WpsData.csdl|res://*/Models.WpsData.ssdl|res://*/Models.WpsData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXXX;initial catalog=XXXX;persist security info=True;user id=XXXX;password=XXXX;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

However, if this connection string is removed and instead specified via the Azure Management Portal, an error occurs.

Name:  DataContext
Value: metadata=res://*/Models.WpsData.csdl|res://*/Models.WpsData.ssdl|res://*/Models.WpsData.msl;provider=System.Data.SqlClient;provider connection string="data source=XXXX;initial catalog=XXXX;persist security info=True;user id=XXXX;password=XXXX;multipleactiveresultsets=True;application name=EntityFramework"
Type:  Custom

This results in the error: No connection string named 'DataContext' could be found in the application config file.

Pukka answered 22/9, 2013 at 18:33 Comment(0)
M
16

See similar question here.

Try leaving the connection string in web.config with some value (either some test connection string, or some dummy value) e.g.

<connectionStrings>
  <add name="DataContext" connectionString="dummy" providerName="System.Data.EntityClient" />
</connectionStrings>
Mara answered 23/9, 2013 at 16:27 Comment(4)
Thanks! It needs to be a dummy value (not empty) or VS complains.Pukka
Why does it need to be a dummy value in the web.config file instead of the original connection string? Why can't you just leave the original value in there so you can continue to run and debug the site locally? Is there something magical about the keyword "dummy"?Magnanimous
@DanCsharpster it can have any value, as long as it's present. Issue in OP's question was that it was missing altogether.Mara
When I try this I get "Format of the initialization string does not conform to specification starting at index 0." error while debuggingEquilateral

© 2022 - 2024 — McMap. All rights reserved.