Hi
public partial class Form1 : Form
{
string ConnectionString = ConfigurationSettings.AppSettings["cnn"];
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Btn_Click_1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
str = "select count(*) from temp where usrname='" + txtusername.Text.Trim() + "' and usrpassword='" + txtpassword.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "login");
long x;
x = Convert.ToInt64(cmd.ExecuteScalar());
if (x == 1)
{
MessageBox.Show("Hello");
}
else
{
MessageBox.Show("Invalid UserName & Password");
}
con.Close();
}
}
Error : The connectionstring property has not been initialised.
App.Config
Data Source=localhost;
Initial Catalog=ha;
Integrated Security=SSPI;
Trusted_Connection=TRUE;" />
Thanks

Priya LingeRank #785 · 2.9K reputationPosted Sep 1, 2011, 11:28 PM EDT
Please check this,
the connection strings are now stored in the connectionStrings node, you'll need to reference them as follows:
ConfigurationManager.ConnectionStrings["cnn"].ConnectionString
ConfigurationManager.AppSettings["ConnectionString"] would be looking in the AppSettings for something
named "ConnectionString",
Hope this will help you.
Thanks.
NarayanRank #8,477 · 221 reputationPosted Sep 1, 2011, 11:20 PM EDT
string ConnectionString =ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Sep 1, 2011, 11:21 PM EDT
Data Source=localhost;
Initial Catalog=ha;
Integrated Security=SSPI;
Trusted_Connection=false;" />