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;
}
先谢谢大家给出错误原因或给以解决.
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;
}
先谢谢大家给出错误原因或给以解决.
Line 33: myConnection.Open();
The ConnectionString property has not been initialized. 这句话有问题
string constr=ConfigurationSettings.AppSettings["Connectionstring"];
检查一下Web.config中有没有名为Connectionstring的配置节
Web.config文件,加上类似下面的内容,数据库用户名密码换成自己的
<appSettings>
<add key="Connectionstring" value="Server=(local);Database=Northwind;user id=sa;password=sa" />
</appSettings>