The ConnectionString property has not been initialized. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.Source Error: 
Line 31:     SqlConnection myConnection=new SqlConnection(constr);
Line 32:     SqlCommand myCommand=new SqlCommand(sqlstr1,myConnection);
Line 33:     myConnection.Open();
Line 34:     Message.Text="";
Line 35:     try{myCommand.ExecuteNonQuery();}
 Source File: C:\Inetpub\wwwroot\Stores\RegCustomer.aspx    Line: 33 Stack Trace: 
[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.SqlClient.SqlConnection.Open() +433
   ASP.RegCustomer_aspx.Submit_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Stores\RegCustomer.aspx:33
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277 
上面是编译错误!
做的是一个用户注册网页,当我输入注册名,密码等项(连接数据库时出现一下错误.能正常显示用户注册页面)出现上面错误!错误代码出错在"提交"安钮事件中.下面为部分代码.
string constr=ConfigurationSettings.AppSettings["Connectionstring"];
SqlConnection myConnection=new SqlConnection(constr);
SqlCommand myCommand=new SqlCommand(sqlstr1,myConnection);
myConnection.Open();
Message.Text="";
try{myCommand.ExecuteNonQuery();}
catch(SqlException ex)
{if(ex.Number==2627)
Message.Text="["+nLoginName.Text+"]"+Inf2.Text;
else
Message.Text="["+ex.Number.ToString()+"]"+ex.Message;
}
myConnection.Close();
if(Message.Text=="")
Message.Text=nLoginName.Text+","+Inf1.Text;
Message.Visible=true;
}
先谢谢大家给出错误原因或给以解决.

解决方案 »

  1.   

    忘了说提示错误是出在
    Line 33:     myConnection.Open();
      

  2.   

    提示已经说清楚了
    The ConnectionString property has not been initialized. 这句话有问题
    string constr=ConfigurationSettings.AppSettings["Connectionstring"];
    检查一下Web.config中有没有名为Connectionstring的配置节
      

  3.   

    怎么检查,Web.config呀,我不知道.能说一下吗,谢谢.
      

  4.   

    就是打开解决方案根目录下的
    Web.config文件,加上类似下面的内容,数据库用户名密码换成自己的
    <appSettings>
    <add key="Connectionstring" value="Server=(local);Database=Northwind;user id=sa;password=sa" />
    </appSettings>