2016-08-07 10 views
0

Ich habe ähnliche Situationen für diesen Fehler auf Stackoverflow gefunden, aber ich denke, mein Problem ist anders, da ich keine Antwort finden konnte.SqlException (0x80131904)

Ich habe eine Website, die ich zu Hause erstellen und auf einem Webhost veröffentlichen, wo sie auch SQL Server für mich liefern. Im Moment kann ich auf SQL Server zugreifen, um mein Menü sowohl auf meinem lokalen Computer als auch nach dem Veröffentlichen zu erstellen, damit das Menü erfolgreich erstellt wird, wenn meine Website live ist. Also, ich weiß, dass die Verbindungszeichenfolge funktioniert.

Jetzt habe ich eine Registrierungsseite sowie eine Anmeldeseite erstellt und beide funktionieren gut auf meinem lokalen Rechner. Doch nach meiner Web-Host-Publishing ich versuchen, einen neuen Benutzer von meiner Website registrieren und diese Fehlermeldung erhalten, wenn ich einreichen getroffen:

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: 26 - Error Locating Server/Instance Specified)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 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: 26 - Error Locating Server/Instance 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.

Hier ist die Zusatzinformation:

<connectionStrings> 
    <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-ffbpools-20160214093044.mdf;Initial Catalog=aspnet-ffbpools-20160214093044;Integrated Security=True" providerName="System.Data.SqlClient" />--> 
    <add name="connstring" connectionString="Data Source=10.23.136.135,780;uid=MyUserName;pwd=~FakePassword1;Initial Catalog=DBaccess_PNM" /> 
    <add name="DBaccess_PNMEntities" connectionString="metadata=res://*/Models.SiteMenuEDModel.csdl|res://*/Models.SiteMenuEDModel.ssdl|res://*/Models.SiteMenuEDModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.23.136.135,780;initial catalog=DBaccess_PNM;persist security info=True;user id=MyUserName;password=~FakePassword1;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    <add name="DBaccess_PNMLoginDetails" connectionString="metadata=res://*/Models.LoginDetailsEDModel.csdl|res://*/Models.LoginDetailsEDModel.ssdl|res://*/Models.LoginDetailsEDModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.23.136.135,780;initial catalog=DBaccess_PNM;persist security info=True;user id=MyUserName;password=~FakePassword1;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 

Und Sie erwähnt der dbcontext, der noch mehr Sinn ergab und ich weitere Recherchen anstellte und herausfand, dass ich einige Migrationen machen musste und den Anweisungen anderer Posts folgen musste: PM> Enable-Migrations -EnableAutomaticMigrations

Aber ich habe die folgende Meldung:

More than one context type was found in the assembly 'ffbpools'. 
To enable migrations for 'ffbpools.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName ffbpools.Models.ApplicationDbContext. 
To enable migrations for 'ffbpools.Models.DBaccess_PNMLoginDetails', use Enable-Migrations -ContextTypeName ffbpools.Models.DBaccess_PNMLoginDetails. 
To enable migrations for 'ffbpools.Models.DBaccess_PNMEntities', use Enable-Migrations -ContextTypeName ffbpools.Models.DBaccess_PNMEntities. 

die Anweisungen Ich habe den folgenden Befehl ein und bekam die Ergebnisse Folgende:

PM> Enable-Migrations -ContextTypeName ffbpools.Models.ApplicationDbContext 
Checking if the context targets an existing database... 
Code First Migrations enabled for project ffbpools. 

Ich dachte, ich war auf dem Weg, bis ich getan habe:

PM> Enable-Migrations -ContextTypeName ffbpools.Models.DBaccess_PNMLoginDetails 
Migrations have already been enabled in project 'ffbpools'. To overwrite the existing migrations configuration, use the -Force parameter. 

ich versuchte, Kraft und bekam:

PM> Enable-Migrations -Force -ContextTypeName ffbpools.Models.DBaccess_PNMLoginDetails 
Checking if the context targets an existing database... 
System.NotSupportedException: Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel. 
    at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) 
    at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w) 
    at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml) 
    at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) 
    at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) 
    at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language, String rootNamespace) 
    at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel. 

Wenn ich genauer hinschaute, fand ich diesen Link: http://forums.asp.net/t/1975675.aspx?Enable+Migrations+says+More+than+one+context+type+was+found+in+the+assembly+ScheduleWeb+ und es scheint, ich kann DBaccess_PNMLoginDetails, DBaccess_PNMEntities und ApplicationDbContext in einem dbcontext kombinieren? Nicht sicher, ob das stimmt! ApplicationDbContext ist etwas, von dem ich glaube, dass ich es zuerst hinzugefügt habe, als ich ursprünglich beschloss, MVC zu lernen. Ich verstehe, wie DBaccess_PNMLoginDetails Kombination DBaccess_PNMEntities in eine DbContext möglich ist, etwas mit so einfach wie:

public class MainDBContext : DbContext 

    { 
      public DbSet<DBaccess_PNMLoginDetails> DBaccess_PNMLoginDetails { get; set; } 
      public DbSet<DBaccess_PNMEntities > DBaccess_PNMEntities { get; set; } 
    } 

aber ApplicationDbContext ist anders und und der Grund, warum ich das denke, weil der Code gefunden.

public partial class DBaccess_PNMLoginDetails : DbContext 
{ 
    public DBaccess_PNMLoginDetails() 
     : base("name=DBaccess_PNMLoginDetails") 
    { 
    } 

Bunch of stuff in here 
} 

Und ..

public partial class DBaccess_PNMEntities : DbContext 
    { 
public DBaccess_PNMEntities() 
      : base("name=DBaccess_PNMEntities") 
     { 
     } 

    Bunch of stuff in here 
    } 

ApplicationDbContext hat nichts so, aber alle drei erstellt ein den gleichen Namensraum von ffbpools. Hier ist, was ich für die ApplicationDbContext haben:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
    { 
     public ApplicationDbContext() 
      : base("DefaultConnection", throwIfV1Schema: false) 
     { 
     } 

     public static ApplicationDbContext Create() 
     { 
      return new ApplicationDbContext(); 
     } 
    } 

Ich hoffe, ich erklärte es gut genug .......

Kann jemand bitte helfen Sie mir dieses Problem lösen?

+0

Wenn Ihr Menü datengesteuert ist und funktioniert, ist die einzige Erklärung, dass diese anderen Operationen Verbindungsinformationen an anderer Stelle erhalten. – Crowcoder

+0

Danke für die Antwort .... Ja, das Menü ist datengesteuert von einer SQL Server-Tabelle und es funktioniert auf meinem lokalen Rechner sowie nachdem ich es auf dem Web-Host veröffentlicht habe. Ich kann mich anmelden und eine Anmeldung von meinem lokalen Server durchführen. Erst nachdem ich die Website auf dem Webhost veröffentlicht habe, kann ich mich nicht mehr anmelden oder einloggen. Ich habe keinen speziellen Code, um zu bestimmen, wann ich lokal oder auf dem Webhost bin, also wie können sie Verbindungsinformationen von woanders bekommen? –

+0

Debuggen und Schritt, wo Sie den dbcontext für die Login-Sachen erstellen, dann überprüfen Sie es, um zu sehen, was seine Verbindungseigenschaften sind. – Crowcoder

Antwort

0

Das hatte damit zu tun, dass ich immer noch lerne und verwirrt wurde, da ich verschiedene Antworten finden würde, ohne zu merken, dass sie nicht zu dem gehörten, was ich tun wollte, nämlich eine Internetseite zu erstellen. Nicht Intranet und nicht Code zuerst.

Jedenfalls habe ich schließlich meine Kontextdateien kombiniert und angefangen, rückwärts zu arbeiten, um zu überprüfen, dass ich zuerst Code für DB schreibe und für eine Internetwebsite.

Verwandte Themen