i need your to help to short out my problem. i m trying to connect my web application to different database. user select the database from user interface i.e asp.net page.the application will connect with that database.
for that i tried to make initial catalog dynamic but not get success. please help.
protected void Button1_Click(object sender, EventArgs e)
{
string db = "";
if (ddlDropdown.SelectedIndex != 0)
{
if (ddlDropdown.SelectedItem.Value == "2013")
{
db = "2013";
}
if (ddlDropdown.SelectedItem.Value == "2014")
{
db = "2014";
}
}
string abc = "Data Source=.;Initial Catalog=" + db + ";Integrated Security=True";
Session["abc"] = abc;
SqlConnection con = new SqlConnection(abc);
con.Open();
Response.Redirect("rrr.aspx");
}
db
value to some default Database instead of initializing to empty string. – Sudhakar Tillapudi Dec 10 '13 at 7:49