aditya immadi

aditya immadi

  • NA
  • 205
  • 71.3k

about connection string

Jun 13 2013 7:50 AM
Hai all,
        i have tried lots of times but i got the error.

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




public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string constring = ConfigurationManager.ConnectionStrings["conn"].ConnectionString();
        SqlConnection conn = new SqlConnection();


       
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "SPuserid";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@name",txtname.Text);
        cmd.Parameters.AddWithValue("@password",txtpwd.Text);
        cmd.Parameters.AddWithValue("@address", txtaddr.Text);
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            Response.Write("name:"+dr[0]);
        }
       
        gv.DataSource = dr;
        gv.DataBind();


        conn.Close();
    }
   
}

And web.config file

<configuration>
 
<connectionStrings>
  <add name="conn" connectionString="Data Source=.;Initial Catalog=june;Persist Security Info=True;User ID=sa;Password=123"
   providerName="System.Data.SqlClient" />
 </connectionStrings>
 <system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>



but i got this error "The ConnectionString property has not been initialized."



can any one fix this

thanks

Answers (5)