ObjectContext problem

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I have below object and while i am debuging i am getting error
Run time error 91
Object variable or with block variable not set error. If i comment out
the Context.SetComplete
Context.SetAbort itworks fine. Also object was working fine. now giving
this error and not compling..I am using MDAC 2.6 and also i have MDAC
2.8 installed too.
using service pack 2 and machine is XP profesionnal. i dont why stop
working and giving this error..
if i use with asp i get this error
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.

Option Explicit
Implements ObjectControl

Const Conn As String = "Provider=SQLOLEDB;Data
Source=NYDB;Database=MYDB;UID=user;PWD=user1"

Private m_objcontext As ObjectContext

Private vSql As String
Private Sub Command1_Click()
Dim str As String
str = GetAccountName(54643)
MsgBox (str)
End Sub


Public Function GetAccountName(ByVal acct As String) As Variant

Dim sql As String
Dim Returninfo As New Collection
Dim oRs As ADODB.Recordset
On Error GoTo GetAccountErrorHandler:

sql = "'" & acct & "'"
vSql = "SELECT ADDRESS FROM ADDRESS "
vSql = vSql & "Where ACCOUNT = " & sql & ""


Set oRs = New ADODB.Recordset

With oRs
.ActiveConnection = Conn
.CursorLocation = adUseServer
.CacheSize = 1
.Open vSql, , adOpenForwardOnly, adLockReadOnly
End With

If Not oRs.EOF Then
GetAccountName = oRs.Fields("ADDRESS").Value
Else
GetAccountName = "Not Found"
End If
oRs.Close
Set oRs = Nothing
m_objcontext.SetComplete

Exit Function
GetAccountErrorHandler:
If IsObject(oRs) Then
oRs.Close
Set oRs = Nothing
End If
m_objcontext.SetAbort
Err.Raise 21500, "blah balh", "Error blah blah - " &
Err.Description

End Function

Private Sub ObjectControl_Activate()
Set m_objcontext = GetObjectContext()
End Sub

Private Sub ObjectControl_Deactivate()
Set m_objcontext = Nothing
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = False
End Function
 
Matt,

Are you sure that this code is in VB.Net. If it is, than I would make it a
little bit more VB.Net style to get it readable as well for us.

To start with that Set beside that option explicit the option strict on

Just my idea,

Cor
 
Horixon,

It is not needed direct to use AdoNet in VB.Net.

Ado can be used as well however not advisable to use that in new projects.
It can be used partially/temporaly in upgrade projects from VB6.

Just as little addition to your message what is of course true.

Cor
 
Back
Top