简体   繁体   中英

Connect to AWS RDS mssql using C#

I'm developing an app that requires a database and I'm attempting to use Amazon Web Service RDS and I have the security set to accept any IP from and port and I'm able to access the database using Microsoft SQL Server Manager, but when I attempt to connect using a test program in C#, I'm not able to establish a connection. I'm not getting a rejected connection, but a connection that can't even find the server. Am I going at this wrong? Here's my test code.

using System;
using System.Diagnostics;
using System.Data.SqlClient;

public static class Program
{
public static void Main(string[] args)
{
    GetConnection();
}

public static void GetConnection()
{
    string ConnectionFormat = "Server={0}; Database={1}; Uid=tie; Pwd=dune";
    string Database = "juniorproject";
    string Server = @"copy pasta,1433";

    using (SqlConnection connection = new SqlConnection(string.Format(ConnectionFormat, Database, Server)))
    {
        Console.WriteLine(connection.ConnectionString);
        connection.Open();
        Console.WriteLine("Success");
    }
}

}

Your server name doesn't even look close to right - it is going to be a much longer string, ie something like this:

myinstance.123456789012.us-east-1.rds.amazonaws.com

you'll need to lookup the actual endpoint in the AWS console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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