I have the below connection string in Web config and works fine in Visual Studio.
我在Web配置中有以下连接字符串,并在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
我尝试使用Azure App服务和Azure AD将我的ASP.NET MVC应用程序移植到Azure。我更改了AttachDbFilename属性,如下所示
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.键'attachdbfilename'的值无效。描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.ArgumentException:键“attachdbfilename”的值无效。源错误:在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
App Data folder does contain the mdf file. How do I refer it in the connection string in web config?
App Data文件夹包含mdf文件。如何在Web配置中的连接字符串中引用它?
Is there any sample program for Azure Web app getting authenticated with Azure AD?
是否有Azure Web应用程序的示例程序通过Azure AD进行身份验证?
2 个解决方案
#1
1
In brief, you cannot use LocalDB in Azure App Service.
简而言之,您无法在Azure App Service中使用LocalDB。
There is another answer - How to connect a localdb from Visual Studio to the published Azure web app?
还有另一个答案 - 如何将Visual Studio中的localdb连接到已发布的Azure Web应用程序?
#2
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.
现在工作正常。在Webconfig中对连接String进行了更改,如下所示。删除了连接字符串中的AttachDBFilename属性,并包含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" />
#1
1
In brief, you cannot use LocalDB in Azure App Service.
简而言之,您无法在Azure App Service中使用LocalDB。
There is another answer - How to connect a localdb from Visual Studio to the published Azure web app?
还有另一个答案 - 如何将Visual Studio中的localdb连接到已发布的Azure Web应用程序?
#2
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.
现在工作正常。在Webconfig中对连接String进行了更改,如下所示。删除了连接字符串中的AttachDBFilename属性,并包含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" />