-2

guys, I'm pretty new, actually a beginner in coding and I got a project from my boss for an app that's gonna access a client's database and send mail with the past activity executing a stored procedure. I've done the application, but now I have a better idea, why configure this and install it on every client's pc when we have Hamachi and we can run in from one our servers by adding multiple connections string especially that every client has the same data base where are creating the stored procedure and execute it. But my question is, how do I add multiple connection strings and make them being accessed one by one by the program (he takes a connection string, he finishes executing, then takes another one and so one until it's finished)

  • What is hamachi? Does it know how to connect to database server and how to execute stored procedure? – Chetan Nov 24 '19 at 12:35
  • ConnectionStrings configuration is just a Key Value pair, so you can easily add multiple. Just give them different names, and most configuration system will give you the collection of connectionstrings so you can iterate through them. – Frank Nielsen Nov 24 '19 at 13:34

1 Answers1

1

It's a little hard to tell from your description, which is not very clear and contains several logical leaps, but it sounds like you want to do something like this:

List<string> connectionStrings = new List<string>();
connectionStrings.Add("Server=myServerAddress;Database=myDataBase1;User Id=myUsername;Password=myPassword;");
connectionStrings.Add("Server=myServerAddress;Database=myDataBase2;User Id=myUsername;Password=myPassword;");

foreach (string connectionString in connectionStrings)
{
    using (var conn = new SqlConnection(connectionString))
    {
        using (var command = new SqlCommand("ProcedureName", conn)) 
        {
            command.CommandType = CommandType.StoredProcedure;
            conn.Open();
            command.ExecuteNonQuery();
        }
    }
}
robbpriestley
  • 3,050
  • 2
  • 24
  • 36