Так что я некоторое время боролся с этой проблемой.Когда я запускаю Update-Database
в Package Manager Console
, я получаю следующий вывод:
System.Data.SqlClient.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
... more errors ...
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:53,State:0,Class:20
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Я подтвердил, что могу подключиться к своей базе данных RDS в SQL Server Management Studio, и я также могу открытьэто в Server Explorer в самой Visual Studio.Я могу запустить Enable-Migrations
без проблем, а также.Ниже приведены строки подключения и где я инициализирую DBContext
.Строка подключения указывается при подключении к моей БД в Visual Studio.
web.config
<connectionStrings>
<add name="dbname" connectionString="Data Source=dbname.xxxxxxxxxxxx.us-east-2.rds.amazonaws.com;Initial Catalog=dbname;User ID=username;Password=password;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient" />
</connectionStrings>
<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>
Context.cs
public class ApplicationContext : DbContext
{
public DbSet<Team> Teams {get; set;}
}
Я сделалподобный проект и раньше, но у меня не было особых проблем со строкой соединения, автоматически подстраивающейся под мою базу данных.Я считаю, что я настроил группы безопасности для своего экземпляра RDS, чтобы обеспечить общедоступный доступ и предоставил доступ ко всем группам безопасности.
Любая помощь будет принята с благодарностью, и если потребуется дополнительная информация, я с радостью предоставлю ее.Я также в состоянии построить и запустить проект отлично.