cannot connect to aws db

253 views Asked by At

i'm trying to create connection to the aws db via c#

string hostname = "databasesql.xxxxx.."
string dbname = "databasesql";
string username = "someuser";
string password = "somepassword"
connectionString = "Data Source=" + hostname + ";Initial Catalog=" + dbname + ";User ID=" + username + ";Password=" + password ;
SqlConnection cnn;
cnn = new SqlConnection(connectionString);
cnn.Open();
Console.WriteLine("Connection Open  !");

i'm getting the error -

System.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=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)
  Source=Core .Net SqlClient Data Provider
  StackTrace:
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at ConsoleAppDBCloud.AWSDBModel.DBConnect() in I:\Visual Studio 2019\Projects\ConsoleAppDBCloud\AWSDB\AWSDBModel.cs:line 46
   at ConsoleAppDBCloud.AWSDBModel..ctor() in I:\Visual Studio 2019\Projects\ConsoleAppDBCloud\AWSDB\AWSDBModel.cs:line 28
   at ConsoleAppDBCloud.Program.Main() in I:\Visual Studio 2019\Projects\ConsoleAppDBCloud\Program.cs:line 11

Inner Exception 1:
Win32Exception: The network path was not found.

i'm trying to check it via telnet

telnet Endpoint port

getting the message Could not open connection to the host, on port xxxx: Connect failed

i checked the parameters that amazon required - public availability and status available but still i see there is an issue with connection. can some advice?

Thanks

1

There are 1 answers

0
Y.D On

After adding the machine+port to the ibound rules, i managed to to telnet to the hostname. now i have an issue of username(Login failed for user) but its a diffrent issue that needs to be resolved. thanks to stdunbar for giving some direction.

enter image description here

enter image description here