Object Variable or With Block Variable not set

I have a VB.NET program which accesses a remote SQL Server 2000 database and executes on logon via the StartUp group in the start menu. The problem I have is that every other time I log in, the program returns an "Object Variable or With Block Variable not set" error. This only happens at logon, when I make it run at any other time it works perfectly, and I am completely stumped. If anyone knows of any problems running applications which access databases at logon, I would be greatful for some help.

Here is the code for the procedure causing the error:

----------

'Sub populates the MainForm with a random info
Public Sub GetItemInfo()
sql_Connection.Open()
With sql_Command
.Connection = sql_Connection
.CommandType = CommandType.Text
.CommandText = "SELECT Frequency_Day, Frequency_Session, SessionNumber FROM Users WHERE Username = '" & Environment.UserName & "'"
sql_Reader = .ExecuteReader
End With
While sql_Reader.Read
If sql_Reader.Item("SessionNumber") = 1 Then
With MainForm
.txtInfo.Text = "This is the first time you have logged in. Please click More to take a DSE Assessment."
.picInfo.Image = "\RJCAPDCpsaimagespopupsdefault.gif"
.btnMoreInfo.Tag = "http://portal.agile-it.net/psa/dse_assessment.aspx?username=" & Environment.UserName
End With
ElseIf sql_Reader.Item("Frequency_Day") Is DBNull.Value Then
If sql_Reader.Item("Frequency_Session") Is DBNull.Value Then
MsgBox("Program error! Please contact system administrator.", MsgBoxStyle.Critical, "Personal Safety Advisor - Critical Error")
Else
If sql_Reader.Item("SessionNumber") Mod sql_Reader.Item("Frequency_Session") <> 0 Then
MainForm.Close()
End If
End If
ElseIf InStr(sql_Reader.Item("Frequency_Day"), Now.DayOfWeek.ToString.Chars(1)) = 0 Then
MainForm.Close()
End If
End While
sql_Reader.Close()
sql_Connection.Close()
Dim rnd As New Random()
With sql_Select
.CommandType = CommandType.Text
.CommandText = "exec dbo.sp_GetInfo " & Environment.UserName & ", " & Environment.MachineName
.Connection = sql_Connection
End With
With sql_Adapter
.SelectCommand = sql_Select
.Fill(sql_Info)
End With
Dim rownum As Integer = rnd.Next(sql_Info.Tables(0).Rows.Count)
With MainForm
.txtInfo.Text = sql_Info.Tables(0).Rows(rownum).Item("PopupText")
.picInfo.Image = MainForm.picInfo.Image.FromFile(sql_Info.Tables(0).Rows(rownum).Item("PopupImage"))
.btnMoreInfo.Tag = sql_Info.Tables(0).Rows(rownum).Item("Hyperlink")
End With
End Sub

----------

And here is the JIT Debugger error message:

----------

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object variable or With block variable not set.
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Popup.mdlSQLFunctions.GetItemInfo()
at Popup.frmMain.frmMain_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/microsoft.net/framework/v1.0.3705/mscorlib.dll
----------------------------------------
Popup
Assembly Version: 0.0.0.0
Win32 Version: 0.0.0.0
CodeBase: file:///C:/Program%20Files/Agile-IT/Personal%20Safety%20Advisor%20Client/Popup.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 7.0.3300.0
Win32 Version: 7.00.9502
CodeBase: file:///c:/winnt/assembly/gac/microsoft.visualbasic/7.0.3300.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
System.Data
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.data/1.0.3300.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system.xml.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 1.0.3300.0
Win32 Version: 1.0.3705.288
CodeBase: file:///c:/winnt/assembly/gac/system.enterpriseservices/1.0.3300.0__b03f5f7f11d50a3a/system.enterpriseservices.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:





When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.


Many thanks!

Andy Kimbrey - Agile-IT

mailto:andrew.kimbrey@agile-it.net

ICQ:78749520
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories