0

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

stdunbar
  • 16,263
  • 11
  • 31
  • 53
Y.D
  • 95
  • 8
  • 2
    Sounds like you have no network connectivity. If you want to connect from an external source you need the db in a public subnet (i.e one with an igw attached) as well as an inbound rule on the secgrp. If the db is in a private subnet (no igw) you need networking between you and the db. – Kisaragi Jul 26 '22 at 19:46
  • in the mongodb you are whiltelisting your IP but here, how can i establish this secgrp? – Y.D Jul 26 '22 at 20:16
  • do you have any example on the secgrp? – Y.D Jul 28 '22 at 18:10
  • i'm using a root user and not iam user, does it have a meaning for the security group or for the extrnal access? – Y.D Jul 28 '22 at 20:14

1 Answers1

0

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

Y.D
  • 95
  • 8