http://www.c-sharpcorner.com/forums/asp-net-how-to-use-class-file-for-connection-in-c-sharp
in this link only singale connection string is in use but i need to declare multiple connection string in class file and use in hole application.
originally its like one application with multiple database. all database having same schema.user select the database name from dropdown then on dropdown selection the user must be redirect to its selected database. means i have to manage multiple connections of database on dropdown selection
my application requires to select the connection string on dropdown selection.

Midhun TpRank #388 · 6.5K reputationPosted Jul 24, 2016, 10:49 PM EDT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
///
/// Summary description for connection
///
public class connection
{
static string my_connection1 = "";
static SqlConnection my_connection = null;
public connection()
{
//
// TODO: Add constructor logic here
//
}
public SqlConnection getconnection(string opt)
{
if (opt == "1")
my_connection1 = ConfigurationManager.ConnectionStrings["connection1"].ConnectionString;
else
my_connection1 = ConfigurationManager.ConnectionStrings["connection2"].ConnectionString;
if (my_connection == null)
{
my_connection = new SqlConnection(my_connection1);
my_connection.Open();
}
return my_connection;
}
}
Chetan Sarode8 reputationPosted Jul 24, 2016, 11:40 PM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jul 24, 2016, 11:59 PM EDT
Chetan Sarode8 reputationPosted Jul 25, 2016, 1:04 AM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jul 25, 2016, 1:26 AM EDT
Chetan Sarode8 reputationPosted Jul 25, 2016, 1:59 AM EDT
Ashiwani SharmaRank #5,816 · 285 reputationPosted Jul 25, 2016, 2:46 AM EDT