Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Help.. for your comment..


Message #1 by "Handoyo Kristanto" <handoyokristanto@t...> on Wed, 20 Nov 2002 09:43:27 -0800
Hi Scott...
I found the answer, use this method :
oR = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

And it's run well..

But i must thanks to you because you help me before ..


Handoyo
-----Original Message-----
From: Scott Isaacs [mailto:isaacs@j...]
Sent: Wednesday, November 20, 2002 7:59 AM
To: ASPX_Professional
Subject: [aspx_professional] RE: Help.. for your comment..


OOPS!   actaully  that wasnt quite correct....  your command wont
execute if you do that

 but you will need to close the connection before the function "returns"

something more like this would be better --
....
	dim oR as OleDbDataReader
	oR = myCommand.ExecuteReader
	myConnection.Close()
	Return oR
....


-----Original Message-----
From: Handoyo Kristanto [mailto:handoyokristanto@t...]
Sent: Wednesday, November 20, 2002 11:43 AM
To: ASPX_Professional
Subject: [aspx_professional] Help.. for your comment..


Hi everyone..

I have a problem about access data from database with ASP.Net.

Why if i use articleHeader() function at my component 2 times there is
always error? But if i use just 1 time there is not error ?

Function :
ObjArticle.ArticleHeader(Article_Id, SqlCmd)

Error message :
The connection is already Open (state=Open).
whereas i always close my connection every time i connect to database
and also i always close my datareader.

Thank you for your help, i will appreciate it ?

regards,
Handoyo

This is my code at aspx file :
 sub Page_Load(obj as object, e as eventargs)
	dim Article_id as string =""
      Article_id = CStr(Request.Params("Article_id"))

	if not page.ispostback = true then

	  dim objReader as OleDbDataReader
	  dim objArticle as new Article

        Dim SqlCmd As String = "CekSourceCode"
	  Dim RecordCount as boolean = false
'-------------> this first function is running well..
        Dim ObjHeader As OleDbDataReader 
ObjArticle.ArticleHeader(Article_Id, SqlCmd)
            'Mengambil nilai jumlah record. Record ada -- true, vice
versa.
            if ObjHeader.Read then
				RecordCount = true
			end if
            ObjHeader.close

			If RecordCount = true  then
                ' Ada Source Code , Source_id = S,xx,xx
                SqlCmd = "ArticleHeaderCode"
'-------------> this the second function (the same function) is error
                objReader = ObjArticle.ArticleHeader(Article_Id, SqlCmd)
                if not objReader is nothing then
	  		objReader.read()
	  		Fullname.text = ObjReader("fullname")

	  		Fullname.NavigateUrl 
"~/User/writter.aspx?UserId=" &
ObjReader("UserId")
			title.text = ObjReader("title")
			level.text = ObjReader("level")
			PostedDate.text =  Format(ObjReader("date"), "d
MMM yyyy")
			downloads.visible = true
			downloads.NavigateUrl= "~/Downloads/" &
ObjReader("Source_id") & ".zip"
			objReader.close()
			end if
            End If 'RecordCount
      end if 'IsPostback
   end sub


This is my function at component file :
Public Function ArticleHeader(ByVal Article_Id As String, ByVal SqlCmd
As
String) As OleDbDataReader
            Dim myCommand As New OleDbCommand(SqlCmd, myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim parameterArticle_Id As New OleDbParameter("@Article_Id",
OleDbType.VarChar, 50)
            parameterArticle_Id.Value = Article_Id
            myCommand.Parameters.Add(parameterArticle_Id)
			myConnection.Open()
			Return myCommand.ExecuteReader
            myConnection.Close()
   End Function


------------------------------------------------------------------------
----

 Ikuti polling TELKOM Memo 166 di www.plasa.com dan menangkan hadiah
masing-masing Rp 250.000 tunai


------------------------------------------------------------------------
----





----------------------------------------------------------------------------

 Ikuti polling TELKOM Memo 166 di www.plasa.com dan menangkan hadiah masing-masing Rp 250.000 tunai

 ----------------------------------------------------------------------------

  Return to Index