简体   繁体   English

来自EC2 ASP.NET IIS7的AWS RDS SQL Server

[英]AWS RDS SQL Server from EC2 ASP.NET IIS7

I have done the following - 我已经完成以下工作-

  • I set up a new EC2 instance running Windows Server 2008 with IIS7. 我设置了一个新的EC2实例,该实例运行带有IIS7的Windows Server 2008。

  • I set up a new RDS Instance running SQL Server 2008 R2. 我设置了一个运行SQL Server 2008 R2的新RDS实例。

  • I have configured the Security Group for the RDS server to allow SQL Server connections on port 1433 from the EC2 instance. 我已经为RDS服务器配置了安全组 ,以允许来自EC2实例的端口1433上的SQL Server连接。

  • On the EC2 instance I can connect to the RDS SQL Database by creating a User or System ODBC Connection from Windows. 在EC2实例上,我可以通过从Windows创建用户或系统ODBC连接来连接到RDS SQL数据库。 I can also connect from my own computer with SQL Management Studio. 我也可以使用SQL Management Studio从自己的计算机进行连接。

When I try to start up my .NET Web Application I get this error 当我尝试启动.NET Web应用程序时,出现此错误

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) 

This is my connection string, I am using Entity Framework and an edmx , Database first . 这是我的连接字符串,我正在使用Entity FrameworkedmxDatabase firstDatabase first

<add name="EntitiesName" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myrdsserver.rds.amazonaws.com;initial catalog=VPN;User Id=userid;Password=password;Persist Security Info=True;MultipleActiveResultSets=True;&quot;" providerName="System.Data.EntityClient" />

I've tried everything in the following links but nothing works to allow me to connect. 我已经尝试了以下链接中的所有内容,但没有任何工作可以连接。

aws ec2 could not open a connection to sql server AWS 2无法打开与SQL Server的连接

entity framework 5 and amazon rds underlying prodiver failed to open 实体框架5和基础Prodiver的Amazon RDS无法打开

can't connect to rds instance from ec2 instance 无法从ec2实例连接到rds实例

UPDATE: I created a Windows .NET Forms application that uses the same connection string and Entity Framework and it works. 更新:我创建了一个Windows .NET Forms应用程序,该应用程序使用相同的连接字符串和Entity Framework并且可以正常工作。 I ran it from the same EC2 instance. 我从同一EC2实例运行它。 It seems that the main difference here is that IIS is not involved with the Windows Form application. 似乎这里的主要区别是Windows Form应用程序不涉及IIS I'm not sure how that is keeping the Web application from working. 我不确定如何使Web应用程序无法正常工作。

Here is the stack trace from the web page: 这是来自网页的堆栈跟踪:

[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) +6573870
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +6600312
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +219
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6602662
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6603203
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +942
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1162
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +72
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +6606457
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +103
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2102
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1079
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6610951
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +233
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +278
   System.Data.SqlClient.SqlConnection.Open() +239
   Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection() +49
   Hangfire.SqlServer.SqlServerStorage..ctor(String nameOrConnectionString, SqlServerStorageOptions options) +279
   Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(IGlobalConfiguration configuration, String nameOrConnectionString) +80
   MyWebApplication1.Startup.Configuration(IAppBuilder app) +39

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +76
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +211
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   Owin.Loader.<>c__DisplayClass1.<LoadImplementation>b__0(IAppBuilder builder) +341
   Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +996
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +119
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +241
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +108
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12618692
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12458309

I found out what this was. 我发现这是什么。 Everything I did in my question was correct and working. 我在问题中所做的一切都是正确的并且可以正常工作。 I had another connection string in the application Startup that was being called for another service. 我在应用程序启动中有另一个连接字符串,正在为另一个服务调用该字符串。 That connection string wasn't updated so it wasn't opening the connection. 该连接字符串未更新,因此未打开连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM