472,984 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

Object not set to a reference to an object 91 - HELP PLEASE

Hi guys,

i am not new to vb6, but a mere tyro in vb.net what i want to do is
the following

open transaction
build an ADODB command object using parameters
execute it
build another command
execute it
build another command
execute it

if all is well commit, else rollback.

my problem is that on the third execute, it dies with the above error.
this error seems to be comming out of cmd.activeconnection.errors
collection. this odd because the connection object and the command
object both show open and in a legitimate state. the collection also
appears to have the right values

any and all help desperately needed. pls don't say use ado.net unless
you are prepared to post equivalent code.

all code is as follows:

** FIRST **
Private Function Add() As Boolean
Dim cmd As ADODB.Command
Dim u As New cUtilites
Dim cn As ADODB.Connection

cn = mdiMain.gDB.Conn

Try
FieldValue("ClientID") = GetNewClientID()
cmd = u.BuildCommand("APP001_InsertEMCApps", RecCol(1))

cn.BeginTrans()

If mdiMain.gDB.Execute(cmd, cn) Then ** OK **
'append names
If Me.Names.Save(FieldValue("clientid"), cn) Then
cn.CommitTrans()
Else
cn.RollbackTrans()
End If
Else
cn.RollbackTrans()
End If
Catch ex As Exception
cn.RollbackTrans()
End Try

cmd = Nothing
u = Nothing

End Function

** SECOND **
Private Function Add(ByVal flds As Collection, Optional ByRef cn As
ADODB.Connection = Nothing) As Boolean
Dim cmd As ADODB.Command
Dim u As New cUtilites

cmd = u.BuildCommand("APP003_InsertEMCNames", flds)
If Not IsNothing(cmd) Then
Add = mdiMain.gDB.Execute(cmd, cn)

Else
Add = False
End If

u = Nothing

End Function

Public Function Save(ByVal ClientID As String, Optional ByRef cn
As ADODB.Connection = Nothing) As Boolean
Dim flds As Collection
If FieldValue("contid", "C") = "" Then
FieldValue("clientid", "C") = ClientID
Save = Add(NamesCol("C"), cn) ** OK **
Else
Update()
End If

If FieldValue("contid", "A") = "" Then
FieldValue("clientid", "A") = ClientID
Save = Add(NamesCol("A"), cn) ** ERROR HERE **
Else
Update()
End If
flds = Nothing

End Function

** THIRD ****

Public Function Execute(ByRef cmd As ADODB.Command, Optional ByRef cn
As ADODB.Connection = Nothing) As Boolean
On Error Resume Next
'very old copied vb6 code
Dim lRecordsAffected As Long

'open connection if ConnectionTo is nothing
With cmd
If cn Is Nothing Then
.ActiveConnection = mCN
Else
.ActiveConnection = cn
End If
.CommandTimeout = 600
.Execute(lRecordsAffected)

End With

With cmd.ActiveConnection ** ERROR HERE AFTER 3RD EXECUTE
**
'put the native error in the errors collection
If .Errors.Count > 0 Then
Err.Raise(.Errors(0).NativeError, .Errors(0).Source,
..Errors(0).Description)
End With
'try catch throw finally
If Err.Number = 0 Then
Execute = True
Else
Execute = False
MsgBox("Error in cDataServices.Execute(). " & Err.Number &
" " & Err.Source & " " & Err.Description)
Err.Clear()
End If

cmd = Nothing

End Function
'builds the command object
Public Function BuildCommand(ByVal SPname As String, ByVal fldCol As
Collection) As ADODB.Command

Dim strSql As String 'SQL string for Error
information
Dim strParams As String 'Param No for Error
information
Dim strNote As String 'Extra error info
Dim cmd As ADODB.Command
Dim FldLen As Integer

cmd = New ADODB.Command

Try
With cmd

.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandText = SPname

'Store all parameter and their values in a string for
error reporting
strParams = "Parameters passed to the SP " & SPname &
" are:"

'Following loop sets all the parameters
For Each fld As PType In fldCol
'Set the parameter for the prepared statement
Select Case fld.Datatype
Case ADODB.DataTypeEnum.adChar,
ADODB.DataTypeEnum.adVarChar
FldLen = IIf(Len(fld.varValue) = 0, 1,
Len(fld.varValue))
Case Else
FldLen = fld.intLen
End Select
'debug
fld.varValue = YesNull(fld.varValue)
strParams = strParams & vbCrLf & "Name = " &
fld.FieldName & " Value = " & fld.varValue
.Parameters.Append(.CreateParameter(fld.FieldName,
fld.Datatype, ADODB.ParameterDirectionEnum.adParamInput, FldLen,
fld.varValue))
Next fld 'End of for loop

End With
Catch e As Exception
cmd = Nothing
MsgBox("build command " & e.Message)
End Try

Return cmd
End Function
Nov 20 '05 #1
0 1490

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
106
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the...
7
by: kon george | last post by:
Can somebody assist. I build this code on a dev laptop and copied across the entire code to a Windows 2003 server with 1.1 framework. It is basic ASP.NE T that uses web service for SQL Server...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
29
by: web1110 | last post by:
If I have 2 variables, A and B, referencing the same object and then do a A.Dispose(), what happens to B?
3
by: BakelNB | last post by:
I am new to the .Net environment, so please bear with me. I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
3
by: Belebele | last post by:
I have an Element class which is abstract and I would like to have an object of the Iterator class to iterate over a range of elements. I would like to use std::for_each to instrument the...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.