簡體   English   中英

如何使我的MVC5應用程序在服務器上運行?

[英]How do i get my MVC5 Application to work on my server?

我首先使用實體​​框架代碼開發一個簡單的MVC5 Asp.Net應用程序。

該應用程序使用LocalDB文件(DefaultConnection.mdf)工作。 雖然在本地一切正常,但將應用程序移動到我的IIS服務器(Windows Server 2012 R2)不會產生預期的結果。

我收到以下錯誤:

建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱正確,並且已將SQL Server配置為允許遠程連接。 (提供者:SQL網絡接口,錯誤:50-發生本地數據庫運行時錯誤。無法創建自動實例。

有關錯誤詳細信息,請參見Windows應用程序事件日志。

我在服務器上安裝了SqlServer LocalDB 2014,但仍然收到錯誤。

知道為什么會這樣嗎?

這是我的web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

固定:我在服務器上安裝了Sql Server Express,並配置了實體框架以與其一起使用。

如果您在Localdb中設置了數據庫,請從項目中刪除EDMX模型,然后添加另一個模型。 執行此操作時,請確保將其連接到服務器上的Localdb實例。 這將在您的web.config文件中創建一個連接字符串。 作為參考,連接字符串應類似於以下內容:

<connectionStrings>
        <add name="Entities" 
             connectionString="metadata=
                 res://*/Context.csdl|res://*/Context.ssdl|res://*/Context.msl;
             provider=System.Data.SqlClient;
             provider connection string=&quot;
             data source=SERVER-IP-ADDRESS-OR-HOSTNAME;
             initial catalog=YOUR-DATABASE;
             user id=SQL-LOGIN;
             password=SQL-PASSWORD;
             multipleactiveresultsets=True;
             application name=EntityFramework&quot;"
             providerName="System.Data.EntityClient" />
</connectionStrings>

除了您的人都在同一條線上。

值得注意的是,當您從服務器運行應用程序時,您可能僅可以使用localhost作為主機名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM