部署到Microsoft Azure网站的Asp.net MVC站点引发错误

时间:2016-11-19 16:16:31

标签: asp.net-mvc asp.net-mvc-4 azure azure-web-sites azure-web-app-service

我正在使用 Visual Studio 2015 更新3。 我有 ASP.NET MVC 4 网站。目标框架:.NET Framework 4.5。该站点有自己的数据库。该站点在本地工作,并与数据库((LocalDb)\v11.0)进行交互。

然后,我使用发布按钮,通过VS将网站部署到 Azure网站。 Web App已成功发布。但是我无法在浏览器中打开它。我在浏览器中收到以下错误:

  应用程序中的服务器错误。

     

系统找不到指定的文件

     

说明:执行期间发生未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息: System.ComponentModel.Win32Exception:系统   找不到指定的文件

     

来源错误:

     

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

堆栈追踪:

[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.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1000
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +800
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +741
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +451
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +108
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +943
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +22
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +139
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +367
   System.Data.SqlClient.SqlConnection.Open() +129
   WebMatrix.Data.Database.EnsureConnectionOpen() +47
   WebMatrix.Data.<QueryInternal>d__0.MoveNext() +67
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +183
   WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +98
   WebMatrix.WebData.DatabaseWrapper.QuerySingle(String commandText, Object[] parameters) +19
   WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(IDatabase db, String tableName) +54
   WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +50
   WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +71
   WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
   WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +55
   OnlineAuction.MvcApplication.SetSecurityOptions() +60
   OnlineAuction.MvcApplication.Application_Start() +51

[HttpException (0x80004005): 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.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +477
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +350
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303

[HttpException (0x80004005): 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.Web.HttpRuntime.FirstRequestInit(HttpContext context) +657
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +96
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189

这是Web.config中的数据库连接字符串:

 <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=OnlineAuctionDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OnlineAuctionDb.mdf" providerName="System.Data.SqlClient"/>

我将整个Web.config文件上传到DropBox

是否存在数据库问题?我已使用VS中的发布按钮发布了整个网站。但可能是数据库没有附加到云网络应用程序?我不确定。如果问题在于缺少数据库,我如何发布与网站关联的数据库以便它们一起工作?

1 个答案:

答案 0 :(得分:1)

问题是网站无法找到或与数据库通信。有几种方法可以做到这一点,但你需要弄清楚你希望如何托管数据库 - 看起来你正在使用SQL,所以你的选择是:

  1. 运行您网站的实例上的SQL Express / LocalDB
  2. Azure SQL DB(将以azure托管并可由您的网站访问)
  3. 在Azure中的VM中托管的SQL Server
  4. 另一个在其他地方(可能在内部)托管的SQL数据库,可以通过混合连接访问
  5. 我建议选项2,因为它为您提供开箱即用的托管解决方案,可以随您的应用扩展,但网络可寻址,因此您的Web应用的多个实例可以共享它,它会自动备份,等等等等。

    或许可以分享一些关于你已经拥有什么或者你想要实现的目标的更多信息?