locked
connection property has not been initialized RRS feed

  • Question

  • hi all

    i am developing winforms application in c#

    My ConnectionString in app.config is 

     

    <add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\UttamPayDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />

    my code is
     try
       {
    
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
        
         SqlCommand cmd = new SqlCommand("select * into " + ctable + " from " + ptable + "");
         con.Open();
         cmd.ExecuteNonQuery();
         con.close();
    }

    at the execution of nonquery it says 
    connection property has not been initialized

     


    Thursday, April 14, 2011 9:56 AM

Answers

  • You forgot to assign the connection to the command:

    cmd.Connction = con;

     

    Hope that helps,

    Dark

     

    • Proposed as answer by Vladimir.Ilic Thursday, April 14, 2011 12:22 PM
    • Edited by darkpwny Thursday, April 14, 2011 12:24 PM typo
    • Marked as answer by HarshilMehta Thursday, April 14, 2011 2:11 PM
    Thursday, April 14, 2011 11:57 AM

All replies

  • You forgot to assign the connection to the command:

    cmd.Connction = con;

     

    Hope that helps,

    Dark

     

    • Proposed as answer by Vladimir.Ilic Thursday, April 14, 2011 12:22 PM
    • Edited by darkpwny Thursday, April 14, 2011 12:24 PM typo
    • Marked as answer by HarshilMehta Thursday, April 14, 2011 2:11 PM
    Thursday, April 14, 2011 11:57 AM
  • thanks darkpwny

    again you helped me..

    it was my mistake..

    Thursday, April 14, 2011 2:11 PM