2013-09-26 19 views
5

Ich habe stundenlang gesucht und kann nichts hilfreiches finden.Azure-Website kann keine Verbindung zur SQL Azure-Datenbank herstellen

Verwenden von ASP.NET MVC4 mit Windows Azure.

Wenn ich die Site lokal auf meinem Dev-Computer mit der SQL Azure-Verbindungszeichenfolge ausführen. Ich kann auf die entfernte Datenbank überhaupt kein Problem zurückgreifen. Allerdings, wenn ich die Website bereitstellen und versuchen, darauf zuzugreifen aus [mysite] .azurewebsites.com ich folgende Fehlermeldung nach einem Timeout erhalten (die Verbindungszeichenfolge in Azure ist identisch, Kopieren und Einfügen):

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. 

SQLExpress database file auto-creation error: 


The connection string specifies a local Sql Server Express instance using a database location 
within the application's App_Data directory. The provider attempted to automatically create the 
application services database because the provider determined that the database does not exist. 
The following configuration requirements are necessary to successfully check for existence of 
the application services database and automatically create the application services database: 

1.If the application is running on either Windows 7 or Windows Server 2008R2, special 
configuration steps are necessary to enable automatic creation of the provider database. 
Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the 
application's App_Data directory does not already exist, the web server account must have read 
and write access to the application's directory. This is necessary because the web server 
account will automatically create the App_Data directory if it does not already exist. 
2.If the application's App_Data directory already exists, the web server account only requires 
read and write access to the application's App_Data directory. This is necessary because the web 
server account will attempt to verify that the Sql Server Express database already exists within 
the application's App_Data directory. Revoking read access on the App_Data directory from the 
web server account will prevent the provider from correctly determining if the Sql Server 
Express database already exists. This will cause an error when the provider attempts to create a 
duplicate of an already existing database. Write access is required because the web server 
account's credentials are used when creating the new database. 
3.Sql Server Express must be installed on the machine. 
4.The process identity for the web server account must have a local user profile. See the readme 
document for details on how to create a local user profile for both machine and domain accounts. 


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.  

Stack Trace: 



[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: 26 - Error Locating Server/Instance Specified)] 
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean 
breakConnection, Action`1 wrapCloseInAction) +5296071 
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean 
callerHasConnectionLock, Boolean asyncClose) +558 
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds 
connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean 
trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5308555 
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String 
newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, 
Boolean withFailover) +145 
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String 
newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString 
connectionOptions, SqlCredential credential, TimeoutTimer timeout) +920 
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, 
SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, 
SecureString newSecurePassword, Boolean redirectedUserInstance) +307 
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, 
SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String 
newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString 
userConnectionOptions) +434 
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, 
DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection 
owningConnection, DbConnectionOptions userOptions) +5311099 
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection 
owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38 
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, 
TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
+5313314 
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, 
DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions 
userOptions) +143 
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +83 
System.Data.SqlClient.SqlConnection.Open() +96 
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, 
Boolean trusted, String connectionString) +76 

[HttpException (0x80004005): Unable to connect to SQL Server database.] 
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, 
Boolean trusted, String connectionString) +131 
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String 
password, Boolean trusted, String connectionString, String database, String dbFileName, 
SqlFeatures features, Boolean install) +89 
System.Web.Management.SqlServices.Install(String database, String dbFileName, String 
connectionString) +27 
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, 
String connectionString) +386 

I mit ftp versucht, an der entfernten Datei web.config zu sehen, aber jedes Mal, wenn ich versuche, „Bereitstellung Anmeldeinformationen einrichten“ ich erhalte diese Fehlermeldung:

Failed to Set Credentials with error: 'Publishing username is already used. Specify a different publishing username.' 

Welche BS ist, weil es kein „Deployment/FTP User“ Set überhaupt.

Jede Hilfe wäre willkommen.

+0

"Die Verbindungszeichenfolge gibt eine lokale Sql Server Express-Instanz an, die den Datenbankspeicherort im App_Data-Verzeichnis der Anwendung verwendet." Es scheint ein Fehler in der Verbindungszeichenfolge zu bestehen, da dieser auf eine Ressource auf Ihrem lokalen Entwicklungscomputer zeigt, die nicht in der azurblauen Box erstellt wurde. Können Sie Ihre web.config posten? Verwenden Sie eine SQL Azure-Datenbank? –

+0

Ich habe das gleiche Problem http://stackoverflow.com/questions/19346938/a-network-releated-or-instance-specific-error-occurred-while-establishing-a-conn aber ich, als ich zuerst gesucht habe ich didn ' Sieh diesen Beitrag. Ich fand, dass in der Konfigurationsdatei des Servers ein Verbindungszeichenfolgenname "LocalSqlServer" ist, der von dem "AspNetSqlMembershipProvider" verwendet wird und das das Problem verursacht hat. Ich habe immer noch keine Lösung. –

Antwort

3

Es scheint, dass die App die falsche Verbindungszeichenfolge verwendet. Manchmal 4 MVC/EF5 hat die Standard-Verbindungszeichenfolge wie folgt:

<add name="MovieDBContext" 
    connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" 
    providerName="System.Data.SqlClient" 
/> 

Für mich ist es immer noch diese Standardverbindung verwendet, das ist vor Ort, warum funktioniert.

Einige Strategien:

1-get die Verbindungszeichenfolge Ihre DbContext wird wie folgt verwendet:

var myconn = db.Database.Connection.ConnectionString; //set this to a ViewBag for example 

2-Nur um sicher zu sein, die Verbindungszeichenfolge in web.config mit dem gleichen Namen erstellen deines DbContext oder setze den Verbindungsnamen im Konstruktor.

ich jetzt, dass Sie bereits die SQL Azure CONNSTRING haben, aber ich werde hier auch in der Post, weil es jemand anderes helfen könnte:

Standard-SQL Azure Connection String

Server=tcp:[serverName].database.windows.net;Database=myDataBase; 
User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False; 
Encrypt=True; 

Sie könnten finden der richtige in Ihrem Management-Portal.

enter image description here

enter image description here

+0

Ich habe das gleiche Problem und versuchte Ihre Vorschläge. Ich habe 2 DataContexte und ich habe die Database.Connection.Connectionstring für beide über einen ViewBag an eine Ansicht gesendet, die nicht geladen werden kann, da eine Verbindung zur Datenbank erforderlich ist. Wenn die Seite die Verbindungszeichenfolge vom ViewBag lädt, stimmt sie mit der korrekten SQL Azure-Zeichenfolge überein, die ich in web.config als meine Standardverbindung festgelegt habe. Ich habe auch versucht, diese Verbindung im Konstruktor für beide DataContexte zu setzen, aber nichts davon scheint das ursprüngliche Problem zu helfen. Irgendwelche anderen Vorschläge für das Reparieren? Vielen Dank. –

0

hatte ich das gleiche Problem vor kurzem in meinem Fall aber die Ursache war anders. Ich hatte die Microsoft ASP.NET Universal Providers konfiguriert, um eine Verbindung zu meiner SQL Azure-Datenbank herzustellen. Später, während ich die ASP.NET Configuration Tool zum Aktivieren von Rollen verwendet habe, sah meine Konfiguration so aus.

<membership defaultProvider="DefaultMembershipProvider"> 
    <providers> 
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="hidden" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="0" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 
    </providers> 
</membership> 
<roleManager enabled="true" /> 

Der Abschnitt roleManager wurde vom Konfigurationstool hinzugefügt. Dieses Werkzeug wurde jedoch in den Tagen der Überlieferung geschrieben, als es keine Universellen Anbieter gab.

Sehen Sie, was fehlt? Ja, im Abschnitt roleManager ist keine Verbindungszeichenfolge definiert.Auf meinem lokalen Computer funktionierte jedoch alles einwandfrei, da diese fehlende Verbindungszeichenfolge dazu führte, dass eine lokale MDF erstellt wurde, in der die App jetzt die Rollen speichern kann. In Azure funktioniert dies jedoch nicht. Ich löste es, indem ich die Verbindungszeichenfolge auf die gleiche Weise wie folgt festlegte:

<membership defaultProvider="DefaultMembershipProvider"> 
    <providers> 
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="hidden" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="0" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 
    </providers> 
</membership> 
<roleManager enabled="true" defaultProvider="DefaultRoleProvider"> 
    <providers> 
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider" connectionStringName="hidden" applicationName="/" /> 
    </providers> 
</roleManager> 

Das Problem gelöst. Ich musste alle meine Rollen neu konfigurieren, weil sie irgendwo in einer lokalen Datei saßen.

0

Ich weiß, das ist ein altes Profil, aber ich möchte meine Lösung teilen.

Mein Problem war, dass ich die Anwendung auf dem lokalen Rechner mit Verbindung zu SQL auf Azure ausführen konnte. Und die Anmeldevalidierung wurde für Azure SQL durchgeführt.

Beim Ausführen der App auf Azure war es nicht möglich, sich anzumelden, aber die Seiten mit anonymem Zugriff stellen eine Verbindung zur Datenbank her.

In der Azure-Verwaltung wird die Verbindungszeichenfolge für DefaultConnection nicht geändert, wenn ein Projekt veröffentlicht wird. Ich denke, diese Verbindung, die ich zum ersten Mal erstellt habe, ist das Projekt zu Azure veröffentlichen. Nachdem die Standardverbindungszeichenfolge auf die gleiche wie in web.config gesetzt wurde, funktioniert alles reibungslos.

1

Die Art und Weise, wie ich dieses Problem löste, war FTP in die Site und heruntergeladen und sah die Verbindungszeichenfolge in web.config.

Es war nicht, was ich erwartet hatte. Ich habe es dann gelöscht und das Problem behoben und die Site erneut veröffentlicht.

Ich wieder FTP auf der Website und jetzt hatte es die richtige Verbindungszeichenfolge.

In meinem Fall war das Problem, dass ich eine web.release.config-Datei verwendete, aber es wurde falsch konfiguriert, so dass es nicht tatsächlich verwendet wurde.

Verwandte Themen