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.
Ashiwani SharmaPosted Jul 25, 2016, 6:46 AM
Chetan SarodePosted Jul 25, 2016, 5:59 AM
Francis SusaimichaelPosted Jul 25, 2016, 5:26 AM
Chetan SarodePosted Jul 25, 2016, 5:04 AM
Francis SusaimichaelPosted Jul 25, 2016, 3:59 AM
Chetan SarodePosted Jul 25, 2016, 3:40 AM
Midhun TpPosted Jul 25, 2016, 2:49 AM
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;
}
}