2016-08-09 6 views
-1

Windows Server 2008 R2システムでVS 2015 ProfessionalにASP.NET MVCアプリケーションを開発していて、アプリケーションがデータベースに接続していますSQL Serverがインストールされていない別のコンピュータ(Windows 10 System)にプロジェクトを移動します。接続先のコンピュータで、私はVS2015 Community Editionを使用しており、プロジェクトをロードすることができました。しかし、プログラムを実行すると、元のコンピュータと同じ名前のデータベースをVisual Studio localdbを使用して作成したにもかかわらず、テーブルが存在しないというエラーが表示されます。 Entity Frameworkとアイデンティティ・フレームワーク(アプリケーションのユーザー管理システムが使用するもの)がテーブルを自動的に生成すると思っていました。管理者ユーザーを作成するためのシードメソッドがありました。Visual Studio 2015プロジェクトを別のコンピュータに移動するときのデータベースの問題

の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> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 

    <connectionStrings> 
    <add name="IdentityDb" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=IdentityDb;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False; MultipleActiveResultSets=True" /> 
    </connectionStrings> 

    <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" /> 
    <add key="owin:AppStartup" value="IdentityDevelopment.App_Start.IdentityConfig" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
    </system.web> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <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.3.0" newVersion="5.2.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
    </system.codedom> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

IdentityConfig.cs

using Microsoft.AspNet.Identity; 
using Microsoft.Owin; 
using Microsoft.Owin.Security.Cookies; 
using Owin; 
using IdentityDevelopment.Infrastructure; 

namespace IdentityDevelopment.App_Start 
{ 
    public class IdentityConfig 
    { 
     public void Configuration(IAppBuilder app) 
     { 

      app.CreatePerOwinContext<AppIdentityDbContext>(AppIdentityDbContext.Create); 
      app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create); 
      app.CreatePerOwinContext<AppRoleManager>(AppRoleManager.Create); 

      app.UseCookieAuthentication(new CookieAuthenticationOptions 
      { 
       AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
       LoginPath = new PathString("/Account/Login"), 
      }); 
     } 
    } 
} 
+0

プロジェクトにはWeb.Configファイルがありますか?投稿できますか? –

+0

@EricSはい、それは投稿しました。これはSQL Server 2008コンピュータからのものです。 – ITWorker

答えて

1

あなたは、EFは、データベースが作成されたレコードを保持して別のシステムにデータベースを移行するEntity Frameworkの移行ツールを使用する必要があり、システムを変更すると、システム名がEFに変更されたので、新しいシステムに移行していることを知らなかったので、EFはそれを新しいデータベースとみなします。msdnデータの移行に役立つ

+0

私はこれを調べます、ありがとう。 – ITWorker

1

Visual Studioでは、Entity Frameworkコードの最初のアプローチ(コードの最初の移行を使用)を使用している場合はテーブルを生成できます。デフォルトでは

は、あなたのEF 設定クラスでは、は、あなたがそれを教えてくれない限り、このプロセスは、自動的に行われないことを意味し、falseに設定されているAutomaticMigrationsEnabled。

あなたは、Visual Studio内のパッケージマネージャコンソールを開き、次のコマンドを入力することができます

Update-Database 

データベースに接続するためのあなたの情報が正確である場合、これは自動的にすべてのあなたの移行や種子法を適用します。複数のプロジェクトがある場合は、パッケージマネージャコンソールで適切なものを選択してください。これは通常、データベースのコンテキストを持つプロジェクトです。

+0

私はこれをこれを試して、今日後で起こるものを掲示します。ありがとう。 – ITWorker

+0

上記のコマンドを実行するとエラーが発生した場合は、トラブルシューティングのために投稿してください。 –

+0

私は移行を読んで、このコマンドを使用して動作させました。 – ITWorker

関連する問題