locked
ExecuteReader: Connection property has not been initialized RRS feed

  • Question

  • User2014701266 posted

    Alright, so I'm not too familiar with data access, so I've basically been fooling around with VB .NET 2003 for the past while at work in an attempt to create a few web forms that we need. I was wondering if anyone would be able to let me know what is wrong with this? The error message is the same at the post subject, and here is the error:

     Source Error:

    Line 160:			oleDbConnection1.Open();
    Line 161:
    Line 162:			System.Data.OleDb.OleDbDataReader rdr = dbCheck.SelectCommand.ExecuteReader();
    Line 163:
    Line 164:			rdr.Read();

    Source File: c:\inetpub\wwwroot\onlineformtestvs\testform\ccpss_login.aspx.cs    Line: 162

    Stack Trace:

    [InvalidOperationException: ExecuteReader: Connection property has not been initialized.]
       System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(String method, Int32& localState)
       System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
       System.Data.OleDb.OleDbCommand.ExecuteReader()
       OnlineFormTestVS.TestForm.CCPSS_Login.invalidID(String famID) in c:\inetpub\wwwroot\onlineformtestvs\testform\ccpss_login.aspx.cs:162
       OnlineFormTestVS.TestForm.CCPSS_Login.Next_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\onlineformtestvs\testform\ccpss_login.aspx.cs:205
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain()
    

     

    Here is my Source:

     

    1    using System;
    2    using System.Collections;
    3    using System.ComponentModel;
    4    using System.Data;
    5    using System.Drawing;
    6    using System.Web;
    7    using System.Web.SessionState;
    8    using System.Web.UI;
    9    using System.Web.UI.WebControls;
    10   using System.Web.UI.HtmlControls;
    11   
    12   namespace OnlineFormTestVS.TestForm
    13   {
    14   	/// <summary>
    15   	/// Summary description for CCPSS_Login.
    16   	/// </summary>
    17   	public class CCPSS_Login : System.Web.UI.Page
    18   	{
    19   		protected System.Web.UI.WebControls.TextBox familyNumber;
    20   		protected System.Web.UI.WebControls.RadioButton rdoMother;
    21   		protected System.Web.UI.WebControls.RadioButton rdoFather;
    22   		protected System.Web.UI.WebControls.Label warning;
    23   		protected System.Data.OleDb.OleDbDataAdapter dbCheck;
    24   		protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
    25   		protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
    26   		protected System.Data.OleDb.OleDbCommand oleDbCommand1;
    27   		protected System.Web.UI.WebControls.Button Next;
    28   		protected System.Data.OleDb.OleDbConnection oleDbConnection1;
    29   		protected System.Data.OleDb.OleDbDataAdapter dbSubmit;
    30   		protected System.Data.OleDb.OleDbCommand oleDbSelectCommand2;
    31   		protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
    32   		protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand2;
    33   		protected System.Web.UI.WebControls.Panel loginPanel;
    34   	
    35   		private void Page_Load(object sender, System.EventArgs e)
    36   		{
    37   			// Put user code to initialize the page here
    38   		}
    39   
    40   		#region Web Form Designer generated code
    41   		override protected void OnInit(EventArgs e)
    42   		{
    43   			//
    44   			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
    45   			//
    46   			InitializeComponent();
    47   			base.OnInit(e);
    48   		}
    49   		
    50   		/// <summary>
    51   		/// Required method for Designer support - do not modify
    52   		/// the contents of this method with the code editor.
    53   		/// </summary>
    54   		private void InitializeComponent()
    55   		{    
    56   			this.dbCheck = new System.Data.OleDb.OleDbDataAdapter();
    57   			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
    58   			this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
    59   			this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
    60   			this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
    61   			this.dbSubmit = new System.Data.OleDb.OleDbDataAdapter();
    62   			this.oleDbSelectCommand2 = new System.Data.OleDb.OleDbCommand();
    63   			this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
    64   			this.oleDbUpdateCommand2 = new System.Data.OleDb.OleDbCommand();
    65   			// 
    66   			// dbCheck
    67   			// 
    68   			this.dbCheck.SelectCommand = this.oleDbSelectCommand1;
    69   			this.dbCheck.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
    70   																							  new System.Data.Common.DataTableMapping("Table", "idList", new System.Data.Common.DataColumnMapping[] {
    71   																																																		new System.Data.Common.DataColumnMapping("familyCode", "familyCode"),
    72   																																																		new System.Data.Common.DataColumnMapping("id", "id")})});
    73   			this.dbCheck.UpdateCommand = this.oleDbUpdateCommand1;
    74   			this.dbCheck.RowUpdated += new System.Data.OleDb.OleDbRowUpdatedEventHandler(this.dbCheck_RowUpdated);
    75   			// 
    76   			// oleDbSelectCommand1
    77   			// 
    78   			this.oleDbSelectCommand1.CommandText = "SELECT familyCode, id FROM idList";
    79   			// 
    80   			// oleDbUpdateCommand1
    81   			// 
    82   			this.oleDbUpdateCommand1.CommandText = "UPDATE idList SET familyCode = ?, id = ? WHERE (id = ?) AND (familyCode = ? OR ? " +
    83   				"IS NULL AND familyCode IS NULL)";
    84   			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("familyCode", System.Data.OleDb.OleDbType.VarWChar, 100, "familyCode"));
    85   			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("id", System.Data.OleDb.OleDbType.Integer, 0, "id"));
    86   			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_id", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
    87   			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_familyCode", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "familyCode", System.Data.DataRowVersion.Original, null));
    88   			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_familyCode1", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "familyCode", System.Data.DataRowVersion.Original, null));
    89   			this.Next.Click += new System.EventHandler(this.Next_Click);
    90   			// 
    91   			// oleDbConnection1
    92   			// 
    93   			this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""C:\Inetpub\wwwroot\OnlineFormTestVS\Database\ConflictDiaries.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Read;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
    94   			// 
    95   			// dbSubmit
    96   			// 
    97   			this.dbSubmit.InsertCommand = this.oleDbInsertCommand1;
    98   			this.dbSubmit.SelectCommand = this.oleDbSelectCommand2;
    99   			this.dbSubmit.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
    100  																							   new System.Data.Common.DataTableMapping("Table", "CCPSS", new System.Data.Common.DataColumnMapping[] {
    101  																																																		new System.Data.Common.DataColumnMapping("Submitter", "Submitter"),
    102  																																																		new System.Data.Common.DataColumnMapping("IP", "IP"),
    103  																																																		new System.Data.Common.DataColumnMapping("Family", "Family"),
    104  																																																		new System.Data.Common.DataColumnMapping("TimeSubmitted", "TimeSubmitted")})});
    105  			this.dbSubmit.UpdateCommand = this.oleDbUpdateCommand2;
    106  			// 
    107  			// oleDbSelectCommand2
    108  			// 
    109  			this.oleDbSelectCommand2.CommandText = "SELECT Submitter, IP, Family, TimeSubmitted FROM CCPSS";
    110  			this.oleDbSelectCommand2.Connection = this.oleDbConnection1;
    111  			// 
    112  			// oleDbInsertCommand1
    113  			// 
    114  			this.oleDbInsertCommand1.CommandText = "INSERT INTO CCPSS(Submitter, IP, Family, TimeSubmitted) VALUES (?, ?, ?, ?)";
    115  			this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
    116  			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Submitter", System.Data.OleDb.OleDbType.Double, 0, "Submitter"));
    117  			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("IP", System.Data.OleDb.OleDbType.VarWChar, 100, "IP"));
    118  			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Family", System.Data.OleDb.OleDbType.VarWChar, 100, "Family"));
    119  			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("TimeSubmitted", System.Data.OleDb.OleDbType.VarWChar, 100, "TimeSubmitted"));
    120  			// 
    121  			// oleDbUpdateCommand2
    122  			// 
    123  			this.oleDbUpdateCommand2.CommandText = "UPDATE CCPSS SET Submitter = ?, IP = ?, Family = ?, TimeSubmitted = ? WHERE (Fami" +
    124  				"ly = ?) AND (TimeSubmitted = ?) AND (IP = ? OR ? IS NULL AND IP IS NULL) AND (Su" +
    125  				"bmitter = ? OR ? IS NULL AND Submitter IS NULL)";
    126  			this.oleDbUpdateCommand2.Connection = this.oleDbConnection1;
    127  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Submitter", System.Data.OleDb.OleDbType.Double, 0, "Submitter"));
    128  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("IP", System.Data.OleDb.OleDbType.VarWChar, 100, "IP"));
    129  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Family", System.Data.OleDb.OleDbType.VarWChar, 100, "Family"));
    130  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("TimeSubmitted", System.Data.OleDb.OleDbType.VarWChar, 100, "TimeSubmitted"));
    131  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Family", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Family", System.Data.DataRowVersion.Original, null));
    132  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_TimeSubmitted", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "TimeSubmitted", System.Data.DataRowVersion.Original, null));
    133  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_IP", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IP", System.Data.DataRowVersion.Original, null));
    134  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_IP1", System.Data.OleDb.OleDbType.VarWChar, 100, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "IP", System.Data.DataRowVersion.Original, null));
    135  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Submitter", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Submitter", System.Data.DataRowVersion.Original, null));
    136  			this.oleDbUpdateCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_Submitter1", System.Data.OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Submitter", System.Data.DataRowVersion.Original, null));
    137  			this.Load += new System.EventHandler(this.Page_Load);
    138  
    139  		}
    140  		#endregion
    141  
    142  		#region bool checkID
    143  		private bool checkID(string famID)
    144  		{
    145  			famID = famID.Trim();
    146  
    147  			if (famID.Length == 0) return false;
    148  
    149  			try { Convert.ToInt32(famID); }
    150  			catch { return false; }
    151  
    152  			char first = famID[0];
    153  
    154  			if ( ( first >= 'a' && first <= 'z') || (first >= 'A' && first <= 'Z') )
    155  			{
    156  				return true;
    157  			}
    158  			
    159  			dbCheck.SelectCommand.CommandText = "SELECT id FROM idlist WHERE id=" + famID + ";";
    160  			
    161  			oleDbConnection1.Open();
    162  
    163  			System.Data.OleDb.OleDbDataReader rdr = dbCheck.SelectCommand.ExecuteReader();
    164  
    165  			rdr.Read();
    166  
    167  			bool toRet = rdr.HasRows;
    168  
    169  			oleDbConnection1.Close();
    170  			
    171  			return toRet;
    172  		}
    173  		#endregion
    174  
    175  		/*public bool checkIfInvalid()
    176  		{
    177  			bool isInvalid = invalidID(familyNumber.Text);
    178  
    179  			if (isInvalid)
    180  			{
    181  				warning.Text = "Error must
    182  			}
    183  		}*/
    184  
    185  		#region int getRBValue(2)
    186  		protected int getRBValue(System.Web.UI.WebControls.RadioButton rb1, System.Web.UI.WebControls.RadioButton rb2)
    187  		{
    188  			if ( rb1.Checked ) 
    189  			{
    190  				return 0;
    191  			}
    192  			else if ( rb2.Checked )
    193  			{
    194  				return 1;
    195  			}
    196  			else
    197  			{
    198  				return -100;
    199  			}
    200  		}
    201  		#endregion
    202  
    203  		#region void Next_Click
    204  		private void Next_Click(object sender, System.EventArgs e)
    205  		{
    206  			bool isInvalid = invalidID(familyNumber.Text);
    207  			bool noParent = !( rdoMother.Checked || rdoFather.Checked );
    208  
    209  			if (!isInvalid && noParent)
    210  			{
    211  				warning.Text="Please enter in you're family number and choose the parent";
    212  				warning.Visible = true;
    213  			}
    214  			else if (!isInvalid && !noParent)
    215  			{
    216  				warning.Text="Please enter in your family number";
    217  				warning.Visible = true;
    218  			}
    219  			else if (isInvalid && noParent)
    220  			{
    221  				warning.Text = "Please choose the parent";
    222  				warning.Visible = true;
    223  			}
    224  			else
    225  			{
    226  				System.Data.OleDb.OleDbParameterCollection pmc = dbSubmit.InsertCommand.Parameters;
    227  
    228  				//Fill in the Standard Fields
    229  				pmc["Family"].Value = familyNumber.Text.Trim();
    230  				pmc["IP"].Value = Request.UserHostAddress.ToString();
    231  				pmc["Submitter"].Value = getRBValue(rdoMother, rdoFather);
    232  
    233  				//open the connection
    234  				dbSubmit.InsertCommand.Connection.Open();
    235  
    236  				//execute the query
    237  				dbSubmit.InsertCommand.ExecuteNonQuery();
    238  
    239  				//close the connection
    240  				dbSubmit.InsertCommand.Connection.Close();
    241  
    242  				Server.Transfer("WebForm1.aspx");
    243  			}
    244  
    245  		}
    246  		#endregion
    247  	}
    248  }
    249  
    Monday, March 10, 2008 4:05 PM

Answers

  • User-744022866 posted

     you are not assigning connection object to the command object. Please assign this before you execute the query

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 11, 2008 12:38 AM
  • User1610800555 posted

    First assign connection string to this.oleDbConnection1

    this.oleDbConnection1  = new this.oleDbConnection1("xxxxxxxxxxxx");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 11, 2008 12:58 AM

All replies

  • User-744022866 posted

     you are not assigning connection object to the command object. Please assign this before you execute the query

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 11, 2008 12:38 AM
  • User1610800555 posted

    First assign connection string to this.oleDbConnection1

    this.oleDbConnection1  = new this.oleDbConnection1("xxxxxxxxxxxx");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 11, 2008 12:58 AM
  • User-744022866 posted

     but you are not assigning this connection to the adapter

     

    please check that 

    Tuesday, March 11, 2008 3:15 AM
  • User229603173 posted

    can you place a response.write(oleDbConnection1.ConnectionString); in line no 100 and check

    Tuesday, March 11, 2008 4:36 AM
  • User2014701266 posted

    Alright well I gave up on trying to do in C#, seeing as how it seems that the everyone seems to be directing me toward VB...so attempt number 21315134651341 this time in VB (n)

    Tuesday, March 11, 2008 3:56 PM