Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 22nd, 2006, 12:04 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default the ConnectionString Property...

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;
        }

    }

  #2 (permalink)  
Old September 22nd, 2006, 12:16 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well the first thing to test is whether ConfigurationManager.AppSettings["strConn"] is returning anything by outputting it somewhere.

--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old September 22nd, 2006, 03:57 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe, sometimes small thing make us mad.

  #4 (permalink)  
Old September 26th, 2006, 02:05 AM
Registered User
 
Join Date: Sep 2006
Location: Pune, Maharashtra, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to lprachande Send a message via Yahoo to lprachande
Default

Great!



Similar Threads
Thread Thread Starter Forum Replies Last Post
ado.connectionstring ankttv Access VBA 4 November 7th, 2008 04:54 PM
where to put my connectionstring pascali70 C# 10 June 22nd, 2007 05:09 AM
The ConnectionString property has not been initial libbydoo ASP.NET 1.0 and 1.1 Basics 6 November 22nd, 2006 10:11 PM
The ConnectionString property has not been initial mar0364 ASP.NET 1.0 and 1.1 Basics 6 March 17th, 2006 11:24 PM
The ConnectionString property...! rajesh0363 All Other Wrox Books 2 July 26th, 2005 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.