473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1514

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'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.