Sql Exception unhandled by user code

Closed
Archana1983 Posts 2 Registration date Thursday October 15, 2015 Status Member Last seen October 16, 2015 - Oct 15, 2015 at 06:31 AM
Archana1983 Posts 2 Registration date Thursday October 15, 2015 Status Member Last seen October 16, 2015 - Oct 16, 2015 at 05:29 AM
I am trying to Retrived datas from Database and store in DropDownlist control Datasource.I am writing code as follows.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;


namespace binding
{
public partial class dataFromTable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

string str = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(str))
{
SqlCommand com = new SqlCommand("Select ID,CityID,CityName,Country from City", con);
con.Open();
DropDownList1.DataSource = com.ExecuteReader();
DropDownList1.DataTextField = "CityName";
DropDownList1.DataValueField = "CityID";
DropDownList1.DataBind();
}


}
}
}

When I am trying to run the program in browser,It shown the following Error:


An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=26285; handshake=912;


Please Anybody Help to solve the problem

1 response

Archana1983 Posts 2 Registration date Thursday October 15, 2015 Status Member Last seen October 16, 2015
Oct 16, 2015 at 05:29 AM
Nobody dont know the answer?
0