c# - 我的网络应用程序在发布时找不到我的数据库

标签 c# asp.net-mvc-3 azure

我使用 MVC3 通过 Visual Studio 2012 创建了一个简单的 Web 应用,并将其发布到 Azure 上。

当我在本地运行它时,一切正常。但是当我发布时,其中有一个使用我创建的数据库的表的页面不会加载。 错误消息很大,但可以这样开始:

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the   file specified

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.

Stack Trace: 


[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296071
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558

继续下去。

共有三个表,一个是 Visual Studio 在其 Web 应用程序示例上创建的默认表。 另外两个是我自己创建的,它们在发布时都不起作用(在本地时运行得很好)。

我假设问题出在连接字符串上,如果我还应该在此处提供更多内容,请询问:

<connectionStrings>
 <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Porta-comprimidos-20130503163319;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Porta-comprimidos-20130503163319.mdf" />
<add name="RemedioDBContext"
  connectionString="Data Source=|DataDirectory|\MeuPortaComprimidosDB.sdf"
  providerName="System.Data.SqlClient"/>
<add name="RemedioTempDBContext"
  connectionString=""
  providerName="System.Data.SqlClient"/>

请问有人可以帮帮我吗?我研究了很多,但不知道如何处理它(是的,我是新手)。

最佳答案

您的连接字符串将数据源设置为LocalDb,默认情况下,Windows Azure 计算机上未安装该数据源,您无法使用它(除非您安装它)。

您必须将数据库迁移到 Windows Azure SQL 并相应地更改您的连接字符串

有关 http://msdn.microsoft.com/en-us/library/windowsazure/ee730904.aspx 的更多信息

关于c# - 我的网络应用程序在发布时找不到我的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16925538/

相关文章:

c# - 使用本地数据库发布项目

asp.net-mvc - 有条件的 ASP.NET MVC Razor 部分

visual-studio-2010 - Visual Studio 数据库项目和 SQL Azure

azure - 在不连接到 Azure 的情况下获取 blob Uri

c# - 如何有效地将一个可观察集合中的范围选择到另一个可观察集合中

c# - 为什么 ReaderWriterLock 在所有者线程终止时不自动释放/退出?

javascript - 如何在 ASP.Net MVC 应用程序中获取客户端时区

asp.net-mvc-3 - knockout 验证和清除控制的正确方法

bash - Azure Devops-如何验证组织中是否存在团队(Azure CLI 或 Azure Bash)

c# - 什么正则表达式可以匹配给定集中相同字符的序列?