DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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)

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links