当前位置: 代码迷 >> ASP.NET >> 错误详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化
  详细解决方案

错误详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化

热度:7214   发布时间:2013-02-25 00:00:00.0
异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化
1、运行环境:Visual   studio2005  
        调试时无错,而连接数据库时报错:
异常详细信息:   System.InvalidOperationException:   ConnectionString   属性尚未初始化
2、源错误(250):

行   248: try
行   249: {
行   250: myConnection.Open();
行   251: myCommand.ExecuteNonQuery();
行   252: myConnection.Close();

堆栈跟踪:
[InvalidOperationException:   ConnectionString   属性尚未初始化。]
      System.Data.SqlClient.SqlConnection.PermissionDemand()   +46
      System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection   outerConnection)   +22
      System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection   outerConnection,   DbConnectionFactory   connectionFactory)   +89
      System.Data.SqlClient.SqlConnection.Open()   +160
      Bid.Person.Login(String   strEmail,   String   strPassword)   in   e:\Visual   Studio   2005\WebSites\WebSite4\App_Code\Person.cs:250
      Default_aspx.btnSubmit_Click(Object   sender,   EventArgs   e)   in   e:\Visual   Studio   2005\WebSites\WebSite4\Default.aspx.cs:42
      System.Web.UI.WebControls.Button.OnClick(EventArgs   e)   +75
      System.Web.UI.WebControls.Button.RaisePostBackEvent(String   eventArgument)   +97
      System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String   eventArgument)   +7
      System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,   String   eventArgument)   +11
      System.Web.UI.Page.RaisePostBackEvent(NameValueCollection   postData)   +33
      System.Web.UI.Page.ProcessRequestMain(Boolean   includeStagesBeforeAsyncPoint,   Boolean   includeStagesAfterAsyncPoint)   +4921

3、错误源代码段:
SqlConnection   myConnection   =   new   SqlConnection(ConfigurationManager.AppSettings[ "ConnectionString "]);
                        SqlCommand   myCommand   =   new   SqlCommand( "sp_person_isp ",   myConnection);
                        HttpContext.Current.Trace.Write( "foo: "   +   ConfigurationManager.AppSettings[ "ConnectionString "]);
                        //   Mark   the   Command   as   a   SPROC
                        myCommand.CommandType   =   CommandType.StoredProcedure;

                        //   Add   Parameters   to   SPROC
                        SqlParameter   prmEmail   =   new   SqlParameter( "@email ",   SqlDbType.VarChar,   255);
                        prmEmail.Value   =   emailaddress;
                        myCommand.Parameters.Add(prmEmail);

                        SqlParameter   prmname   =   new   SqlParameter( "@name ",   SqlDbType.VarChar,   255);
  相关解决方案