Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

receive "TNS-XXXX: no listener" from ORACLE

Status
Not open for further replies.

dafty

Programmer
Jul 21, 2001
40
TH
I can't success my work cause msgbox "TNS : no listener" .
when i wrote VB form->
-----------
sub buut1_click()
dim orasession1,oradb1 as object

set orasession1 = createobject("XSESION.ORASESSION")
set oradb1= orasesstion1.opendatabase(&quot;MY_NET_SERVICE&quot; ,&quot;scott/tiger&quot;,&0) <------- this line error

end sub
------------------
i have no idea about listener.
 
Are you able to successfully do a TNSPING80 to your server?

Chip H.
 
Thank chiph,
but i find a new problem,..
i success my program running ,but when i run it again error message &quot; Run-time error '-2147417848(80010108)' : method 'OpenDatabase' of object '_IOraSession' failed &quot;
appeared to me ,when i restart VB6 and run project again it no error found !. i don't understand ,do oracle want to close this object? or my fail.
 
Yes, any objects that you use or create ought to be closed and set to Nothing when you're through with them. What's probably happening is Oracle thinks you've already got a session open, and is complaining about you creating another one.

What I do when I've got a resource that I must ensure that I clean up, is write what I call &quot;sandwich code&quot;. I write the open statement, and immediately write the needed close/cleanup statements. That way I don't forget to do it later.

Chip H.

BTW, &quot;Sandwich&quot; implies that you write the bread, and the meat is the code that makes use of the structure that the bread provides.
 
thank u chiph,
can you exam for this case
 
I'm sorry, I don't understand what you mean by 'can I exam for this case' ?

Chip H.
 
to chiph,
i mean code for finishing using object like a close object.
 
OK, I think I understand now.
To close and clean up an ADO connection, you'd do something like this:
[tt]
If Not objADORecordset is Nothing Then
[tab]If objADORecordset.State = adStateOpen Then
[tab][tab]objADORecordset.Close
[tab]End If
[tab]Set objADORecordset= Nothing
End If
Set objADOCommand = Nothing
If Not objADOConnection is Nothing Then
[tab]If objADOConnection .State = adStateOpen Then
[tab][tab]objADOConnection .Close
[tab]End If
[tab]Set objADOConnection = Nothing
End If
[/tt]

So, if the recordset object exists, you test to see if it's still open. If it is, you close it. You then set it to Nothing (which frees the memory it used). With an ADO Command object, you don't close it, so you just set it to nothing. No need to test to see if it exists, as it's always OK to set an object variable to Nothing, even if it's already Nothing. The ADO Connection object gets freed the same way as the Recordset object.

The way you use this code is by setting up an error handler in your code:
[tt]
Public Function MyFunction() as Boolean

[tab]Dim objADORS as ADODB.Recordset

[tab]On Error Goto MyFunction_ErrHandler
[tab]MyFunction = False 'Assume failure

[tab]Set objADORS = New ADODB.Recordset

[tab]' code that does stuff goes here

[tab]MyFunction = True
[tab]Goto MyFunction_Cleanup

MyFunction_ErrHandler:
[tab]'Code to log errors

[tab]' Fall through into cleanup

MyFunction_Cleanup:
[tab]' Code like I showed you above to
[tab]' clean up objects
End Function
[/tt]

Hope this helps.

Chip H.

 
Keos -

In case you didn't know, in .NET you don't need to set objects to Nothing, as the runtime garbage collector does it for you when it determines that the object can no longer be reached by your code. It even handles circular references (A->B->C->A). Your .NET code then becomes much smaller than the VB6 equivalent.

Chip H.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top