2014-12-18 4 views
0

Я сейчас застрял в ситуации, когда я не знаю, как это сделать. Для веб-сайта, над которым я работаю, если у меня нет пользователя, я могу получить доступ к страницам, которые требуют использования информации БД. Когда я вхожу в систему, я получаю ошибку, указанную в заголовке.«При установлении соединения с SQL Server возникла связанная с сетью или конкретная ошибка экземпляра».

Моя база данных и веб-сайт размещаются через облачную службу Azure, используя бесплатную пробную версию, и у меня также включен Role Manager в режиме web.config (отключение этого метода избавляет от ошибки, но мне нужно, чтобы она была включена для проверки роли). Все работает нормально, когда я нахожусь в локальном хосте, так что только когда мой сайт развернут, у меня возникают проблемы.

Я новичок в ASP.NET, поэтому я по-прежнему потерял некоторые основы того, как это работает.

** EDIT: ** здесь мой файл web.config с помощью добавленного кода из timeiscoffee

<?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="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Entertainist-20141207110857.mdf;Initial Catalog=aspnet-Entertainist-20141207110857;Integrated Security=True" providerName="System.Data.SqlClient" /> 
    </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" /> 
    </appSettings> 
    <system.web> 
    <customErrors mode="Off" /> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <roleManager enabled="true" 
    defaultProvider="SqlRoleProvider"> 
     <providers> 
     <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" 
     connectionStringName="DefaultConnection" 
     applicationName="Entertainist"/> 
     </providers> 
    </roleManager> 
    <globalization culture="en-US" uiCulture="auto:en-US" /> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="FormsAuthentication" /> 
    </modules> 
    </system.webServer> 

    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="CalculatorServiceBehavior"> 
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" 
           roleProviderName="SqlRoleProvider" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 


    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <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.Helpers" 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.2.0" newVersion="5.2.2.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="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <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> 

А вот мой Configuration.cs файл, который устанавливает роли и добавляет данные семян в базу данных

namespace Entertainist.Migrations 
{ 
    using Entertainist.Models; 
    using Microsoft.AspNet.Identity; 
    using Microsoft.AspNet.Identity.EntityFramework; 
    using System; 
    using System.Data.Entity; 
    using System.Data.Entity.Migrations; 
    using System.Linq; 

    internal sealed class Configuration : DbMigrationsConfiguration<Entertainist.Models.ApplicationDbContext> 
    { 
     public Configuration() 
     { 
      AutomaticMigrationsEnabled = true; 
      ContextKey = "Entertainist.Models.ApplicationDbContext"; 
     } 

     protected override void Seed(Entertainist.Models.ApplicationDbContext context) 
     { 

      var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); 
      var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context)); 

      // Create Admin Role 
      string roleName = "Admins"; 
      IdentityResult roleResult; 

      // Check to see if Role Exists, if not create it 
      if (!RoleManager.RoleExists(roleName)) 
      { 
       roleResult = RoleManager.Create(new IdentityRole(roleName)); 
      } 

      context.Artists.AddOrUpdate(
       a => a.ArtistName, 
       new Artist { ArtistName = "Kanye West" }, 
       new Artist { ArtistName = "65daysofstatic"}, 
       new Artist { ArtistName = "D'Angelo"}, 
       new Artist { ArtistName = "Faith No More"}, 
       new Artist { ArtistName = "Daft Punk" }, 
       new Artist { ArtistName = "Lana Del Rey"}, 
       new Artist { ArtistName = "The Decemberists"}, 
       new Artist { ArtistName = "The War On Drugs"} 
       ); 

      context.MusicGenres.AddOrUpdate(
       g => g.GenreName, 
       new MusicGenre { GenreName = "Rock" }, 
       new MusicGenre { GenreName = "Hip-Hop" }, 
       new MusicGenre { GenreName = "Electronic" }, 
       new MusicGenre { GenreName = "Country" }, 
       new MusicGenre { GenreName = "Classical" }, 
       new MusicGenre { GenreName = "Indie"}, 
       new MusicGenre { GenreName = "Rap"}, 
       new MusicGenre { GenreName = "Metal"}, 
       new MusicGenre { GenreName = "Pop"} 
       ); 

      context.MovieGenres.AddOrUpdate(

       g => g.GenreName, 
       new MovieGenre { GenreName = "Adventure"}, 
       new MovieGenre { GenreName = "Action"}, 
       new MovieGenre { GenreName = "Anime"}, 
       new MovieGenre { GenreName = "Bollywood"}, 
       new MovieGenre { GenreName = "Sci-Fi"}, 
       new MovieGenre { GenreName =" Independent"}, 
       new MovieGenre { GenreName = "Fantasy"} 

       ); 


      context.Studios.AddOrUpdate(
       s => s.StudioName, 
       new Studio { StudioName = "Universal"}, 
       new Studio { StudioName = "MGM"}, 
       new Studio { StudioName = "Disney"}, 
       new Studio { StudioName = "Bad Robot"}, 
       new Studio { StudioName = "Studio Ghibli"}, 
       new Studio { StudioName = "Pixar"} 
       ); 

      context.Directors.AddOrUpdate(
       d => d.DirectorName, 
       new Director { DirectorName = "Steven Spielberg"}, 
       new Director { DirectorName = "Michael Bay"}, 
       new Director { DirectorName = "James Cameron"}, 
       new Director { DirectorName = "Ang Lee"}, 
       new Director { DirectorName = "J.J. Abrams"}, 
       new Director { DirectorName = "Hayao Miyazaki"} 

       ); 

      // This method will be called after migrating to the latest version. 

      // You can use the DbSet<T>.AddOrUpdate() helper extension method 
      // to avoid creating duplicate seed data. E.g. 
      // 
      // context.People.AddOrUpdate(
      //  p => p.FullName, 
      //  new Person { FullName = "Andrew Peters" }, 
      //  new Person { FullName = "Brice Lambson" }, 
      //  new Person { FullName = "Rowan Miller" } 
      // ); 
      // 
     } 
    } 
} 
+0

Новое в StackOverflow, а я вижу. Помните, показывая некоторые из кода, который у вас есть, чтобы дать людям что-то работать? – CalebB

ответ

0

Вы Продвинутый RoleProvider, чтобы использовать базу данных сервиса azure cloud? если нет, возможно, он пытается использовать sqlexpress, поэтому он будет работать на вашем локальном компьютере, но не при развертывании.

http://msdn.microsoft.com/en-us/library/aa702542(v=vs.110).aspx

+0

Я добавил код, который был в указанной вами ссылке, и теперь я получаю новую ошибку, в которой говорится: «Не удалось найти хранимую процедуру dbo.aspnet_CheckSchemaVersion». – jarrodthibodeau

+0

Похоже, вам нужно запустить aspnet_regsql.exe против вашей целевой базы данных, чтобы настроить схему. –

Смежные вопросы

 Смежные вопросы