System.InvalidOperationException: ExecuteReader: Connection property has not been initialized
Hi, I'm a newbie and I have this problem when working with a user control:
System.InvalidOperationException: ExecuteReader: Connection property has not
been initialized
It is a simple User Control, with just a sql connection string and a stored
procedure:
----------------------------------------------------------------------------
--------
SqlConexio = New System.Data.SqlClient.SqlConnection()
SqlConexio.ConnectionString = "the connection string - I don't write in the
forum for obvious reasons, but I know it's OK"
'the Stored Procedure
cmdIncrementarComptador = New System.Data.SqlClient.SqlCommand()
cmdIncrementarComptador.CommandText = "qe842.[Bruno_Comptador_Seleccio]"
cmdIncrementarComptador.CommandType =
System.Data.CommandType.StoredProcedure
cmdIncrementarComptador.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
SqlConexio.Open()
cmdIncrementarComptador.ExecuteNonQuery()
SqlConexio.Close()
--------------------------------------------------------------
The error appears when Executing the Stored Procedure...
any ideas? TIA
Re: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized
On Sun, 15 Sep 2002 00:28:12 +0200, "Elmosca" <elmosca@terra.es> wrote:
¤ Hi, I'm a newbie and I have this problem when working with a user control:
¤
¤ System.InvalidOperationException: ExecuteReader: Connection property has not
¤ been initialized
¤
¤ It is a simple User Control, with just a sql connection string and a stored
¤ procedure:
¤
¤ ----------------------------------------------------------------------------
¤ --------
¤ SqlConexio = New System.Data.SqlClient.SqlConnection()
¤ SqlConexio.ConnectionString = "the connection string - I don't write in the
¤ forum for obvious reasons, but I know it's OK"
¤
¤ 'the Stored Procedure
¤ cmdIncrementarComptador = New System.Data.SqlClient.SqlCommand()
¤ cmdIncrementarComptador.CommandText = "qe842.[Bruno_Comptador_Seleccio]"
¤ cmdIncrementarComptador.CommandType =
¤ System.Data.CommandType.StoredProcedure
¤ cmdIncrementarComptador.Parameters.Add(New
¤ System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
¤ System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
¤ False, CType(10, Byte), CType(0, Byte), "",
¤ System.Data.DataRowVersion.Current, Nothing))
¤
¤ SqlConexio.Open()
¤ cmdIncrementarComptador.ExecuteNonQuery()
¤ SqlConexio.Close()
¤
¤ --------------------------------------------------------------
¤ The error appears when Executing the Stored Procedure...
¤ any ideas? TIA
I don't see where you've specified the SqlConnection for your SqlCommand object:
cmdIncrementarComptador.Connection = SqlConexio
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)