System.InvalidOperationException: ExecuteReader: Connection property has not been initialized


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized

  1. #1
    Elmosca Guest

    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



  2. #2
    Paul Clement Guest

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center