title: ExecuteNonQuery: Connection property has not been initialized.
body: <p>Afternoon,
           So I have been at this one issue for hours and can't really get past this last hump.  Below is the code for this program that I am writing:  </p>
  
  <pre><code>using System;  
  using System.Collections.Generic;  
  using System.Linq;  
  using System.Text;  
  using System.Diagnostics;  
  using System.Data;  
  using System.Data.SqlClient;  
  using System.Configuration;  
  
  namespace Test  
  {  
    class Program  
    {  
      static void Main()  
      {  
        EventLog alog = new EventLog();  
        alog.Log = "Application";  
        alog.MachineName = ".";  
        foreach (EventLogEntry entry in alog.Entries)  
        {  
         SqlConnection connection1 = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=syslog2;Integrated Security=True");  
         SqlDataAdapter cmd = new SqlDataAdapter();  
         cmd.InsertCommand = new SqlCommand("INSERT INTO Application VALUES (@EventLog, @TimeGenerated, @EventType, @SourceName, @ComputerName, @InstanceId, @Message) ");  
         cmd.InsertCommand.Parameters.Add("@EventLog",SqlDbType.VarChar).Value = alog.Log;  
         cmd.InsertCommand.Parameters.Add("@TimeGenerated", SqlDbType.DateTime).Value = entry.TimeGenerated;  
         cmd.InsertCommand.Parameters.Add("@EventType", SqlDbType.VarChar).Value = entry.EntryType;  
         cmd.InsertCommand.Parameters.Add("@SourceName", SqlDbType.VarChar).Value = entry.Source;  
         cmd.InsertCommand.Parameters.Add("@ComputerName", SqlDbType.VarChar).Value = entry.MachineName;  
         cmd.InsertCommand.Parameters.Add("@InstanceId", SqlDbType.VarChar).Value = entry.InstanceId;  
         cmd.InsertCommand.Parameters.Add("@Message", SqlDbType.VarChar).Value = entry.Message;  
         connection1.Open();  
         cmd.InsertCommand.ExecuteNonQuery();  
         connection1.Close();  
        }   
      }  
    }  
  } 
  </code></pre>
  
  <p>The Code compiles fine without error or warning but when i go to run it, as soon as it gets to cmd.InsertCommand.ExecuteNonQuery(); I get the following error: </p>
  
  <blockquote>
    <p>ExecuteNonQuery: Connection property has not been initialized.  </p>
  </blockquote>
  
  <p>Any ideas on what I missed?</p>