Subject: the ConnectionString Property...
Posted By: coolb Post Date: 9/22/2006 12:04:38 PM
Hello there, I have got an error like 'the ConnnectionString property has not been initialized. Anybody has any idea. Here is my code...

SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["strConn"]);
        SqlCommand myCmd = new SqlCommand("sp_userValidation", myConn);
        myCmd.CommandType = CommandType.StoredProcedure;

        SqlParameter objParamUser;
        SqlParameter objParamPwd;
        SqlParameter returnParam;

        objParamUser = myCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
        objParamPwd = myCmd.Parameters.Add("@Password", SqlDbType.VarChar);
        returnParam = myCmd.Parameters.Add("@Num_of_User", SqlDbType.Int);

        objParamUser.Direction = ParameterDirection.Input;
        objParamPwd.Direction = ParameterDirection.Input;
        returnParam.Direction = ParameterDirection.ReturnValue;

        objParamUser.Value = txtEmail.Value;
        objParamPwd.Value = txtPassword.Value;

        try
        {
            if (myConn.State.Equals(ConnectionState.Closed))
            {
                myConn.Open();
                myCmd.ExecuteNonQuery();
            }
            if ((int)returnParam.Value < 1)
            {
                lblMessage.Text = "Invalid Login!";
                return false;
            }
            else
            {
                myConn.Close();
                return true;
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex + "Error Connecting to the database";
            return false;
        }

    }

Reply By: joefawcett Reply Date: 9/22/2006 12:16:36 PM
Well the first thing to test is whether ConfigurationManager.AppSettings[ strConn is returning anything by outputting it somewhere.

--

Joe (Microsoft MVP - XML)
Reply By: coolb Reply Date: 9/22/2006 3:57:21 PM
Thanks Joe, sometimes small thing make us mad.

Reply By: lprachande Reply Date: 9/26/2006 2:05:54 AM
Great!


Go to topic 49446

Return to index page 165
Return to index page 164
Return to index page 163
Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156