9

I have the below connection string in Web config and works fine in Visual Studio.

<connectionStrings>
   <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MyPortal-20170627104450.mdf;Initial Catalog=aspnet-MyPortal-20170627104450;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

I tried porting my ASP.NET MVC application to Azure using Azure App service and Azure AD. I changed AttachDbFilename attribute as below

AttachDbFilename=\App_Data\aspnet-MyPortal-20170620051631.mdf

I am getting below error:

Invalid value for key 'attachdbfilename'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

App Data folder does contain the mdf file. How do I refer it in the connection string in web config?

Is there any sample program for Azure Web app getting authenticated with Azure AD?

mikalai
  • 1,746
  • 13
  • 23
ramesh
  • 101
  • 1
  • 4

2 Answers2

1

In brief, you cannot use LocalDB in Azure App Service.

There is another answer - How to connect a localdb from Visual Studio to the published Azure web app?

mikalai
  • 1,746
  • 13
  • 23
  • Let me clarify the problem again. The .NET MVC web app that we created is working fine when running from visual studio. It is able to connect to Azure SQL DB and Azure AD. When I deployed this app by creating a Azure App service, I am getting the earlier mentioned error in the Azure AD authentication step. When I bypass AD authentication step, the App works fine connecting to Azure SQL DB. My guess is the Azure web app is not recognizing the App_Data folder under wwwroot, so trying different ways in the connection string without much success. Can somebody help please? – ramesh Jul 03 '17 at 05:18
1

working fine now. Made changes to connection String in Webconfig as below. Removed the AttachDBFilename attribute in the connection string and included the Azure DB.

<add name="DefaultConnection" connectionString="Server = tcp:myserverazure2017.database.windows.net,1433; Initial Catalog = MyDBPro; Persist Security Info = False; User ID = ****; Password = ****; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;" providerName="System.Data.SqlClient" />

ramesh
  • 101
  • 1
  • 4