T
tshad
I have a problem with a VS 2003 project.
This project was designed and works fine in VS 2003.
But trying to open the project I get the following error.
************************************************************
The class EmailPoller can be designed, but is not the first class in the
file. Visual Studio requires that designers use the first class in the
file. Move the class code so that it is the first class in the file and try
loading the designer again.
**************************************************************
Not sure why this is a problem. This is a Windows Service I am creating
with 3 Classes:
CMailMessage
EmailPoller (the offending Class)
Project Installer.
There are 2 files:
EmailPoller.vb
ProjectInstaller.vb (which is created automatically).
In the following code, do I just move the "Class CmailMessage" code to the
bottom of the source file?
If that is the case, why?
I didn't have to do that in VS 2002.
The first part of the EmailPoller.vb file is:
**************************************************
Imports System.ServiceProcess
Imports System.Web.Mail
Imports System.Data.SqlClient
Imports System.IO
Class CEmailMessage
Public id As Integer
Public strTo As String
Public strCC As String
Public strBCC As String
Public strFrom As String
Public strSubject As String
Public strBody As String
Public isHTML As Integer
Public dateAttempted As Date
Public status As Integer
Public errMessage As String
End Class
Public Class EmailPoller
Inherits System.ServiceProcess.ServiceBase
Friend WithEvents cmd_get_poller_settings As
System.Data.SqlClient.SqlCommand
Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Const ATTEMPTED = 2
Const SENT = 3
Dim strProgress As String
#Region " Component Designer generated code "
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call
'LogInfo("Completed New()")
End Sub
'UserService overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
'LogInfo("In Dispose()")
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' The main entry point for the process
<MTAThread()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New
EmailPoller()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
Friend WithEvents EmailQueueTimer As System.Timers.Timer
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Friend WithEvents da_get_messages As
System.Data.SqlClient.SqlDataAdapter
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.EmailQueueTimer = New System.Timers.Timer()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
Me.da_get_messages = New System.Data.SqlClient.SqlDataAdapter()
Me.cmd_get_poller_settings = New System.Data.SqlClient.SqlCommand()
Me.cmd_update_msg = New System.Data.SqlClient.SqlCommand()
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
CType(Me.EmailQueueTimer,
System.ComponentModel.ISupportInitialize).BeginInit()
'LogInfo("Init EmailQueueTimer")
'
'EmailQueueTimer
'
Me.EmailQueueTimer.Enabled = True
Me.EmailQueueTimer.Interval = 10000
'
'LogInfo("Init SqlConnection1")
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=VENUS;initial
catalog=FTSolutions;password=web4pay;persist security i" & _
"nfo=True;user id=ftsweb;workstation id=PROGRAMMER1;packet
size=4096"
'
'da_get_messages
'
Me.da_get_messages.SelectCommand = Me.SqlSelectCommand1
'
'cmd_get_poller_settings
'
Me.cmd_get_poller_settings.CommandText =
"dbo.[COM_GET_EMAIL_QUEUE_SETTINGS_SP]"
Me.cmd_get_poller_settings.CommandType =
System.Data.CommandType.StoredProcedure
Me.cmd_get_poller_settings.Connection = Me.SqlConnection1
Me.cmd_get_poller_settings.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_msg.CommandText =
"dbo.[COM_UPDATE_EMAIL_QUEUE_MSG_STATUS_SP]"
Me.cmd_update_msg.CommandType =
System.Data.CommandType.StoredProcedure
Me.cmd_update_msg.Connection = Me.SqlConnection1
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@status", System.Data.SqlDbType.TinyInt,
1, System.Data.ParameterDirection.Input, False, CType(3, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@date_attempted",
System.Data.SqlDbType.DateTime, 8))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@error_message",
System.Data.SqlDbType.VarChar, 100))
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText =
"dbo.[COM_GET_EMAIL_QUEUE_MESSAGES_SP]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@quantity", System.Data.SqlDbType.Int,
4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
'
'EmailPoller
'
Me.CanPauseAndContinue = True
Me.ServiceName = "EmailPoller"
CType(Me.EmailQueueTimer,
System.ComponentModel.ISupportInitialize).EndInit()
End Sub
#End Region
Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("EmailPoller Started")
EmailQueueTimer.Start()
End Sub
Protected Overrides Sub OnStop()
'LogInfo("EmailPoller Stopped")
EmailQueueTimer.Stop()
End Sub
Private Sub EmailQueueTimer_Elapsed(ByVal sender As System.Object, ByVal
e As System.Timers.ElapsedEventArgs) Handles EmailQueueTimer.Elapsed
'LogInfo("EmailPoller Timer Interval")
PollAndSendEmail()
End Sub
Private Sub PollAndSendEmail()
Try
'LogInfo("PollAndSend() Starting")
Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessages As
Integer
Dim DR As SqlDataReader
' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnection()
strProgress = "About to execute the reader"
***************************************************
Thanks,
Tom
This project was designed and works fine in VS 2003.
But trying to open the project I get the following error.
************************************************************
The class EmailPoller can be designed, but is not the first class in the
file. Visual Studio requires that designers use the first class in the
file. Move the class code so that it is the first class in the file and try
loading the designer again.
**************************************************************
Not sure why this is a problem. This is a Windows Service I am creating
with 3 Classes:
CMailMessage
EmailPoller (the offending Class)
Project Installer.
There are 2 files:
EmailPoller.vb
ProjectInstaller.vb (which is created automatically).
In the following code, do I just move the "Class CmailMessage" code to the
bottom of the source file?
If that is the case, why?
I didn't have to do that in VS 2002.
The first part of the EmailPoller.vb file is:
**************************************************
Imports System.ServiceProcess
Imports System.Web.Mail
Imports System.Data.SqlClient
Imports System.IO
Class CEmailMessage
Public id As Integer
Public strTo As String
Public strCC As String
Public strBCC As String
Public strFrom As String
Public strSubject As String
Public strBody As String
Public isHTML As Integer
Public dateAttempted As Date
Public status As Integer
Public errMessage As String
End Class
Public Class EmailPoller
Inherits System.ServiceProcess.ServiceBase
Friend WithEvents cmd_get_poller_settings As
System.Data.SqlClient.SqlCommand
Friend WithEvents cmd_update_msg As System.Data.SqlClient.SqlCommand
Friend WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
Const ATTEMPTED = 2
Const SENT = 3
Dim strProgress As String
#Region " Component Designer generated code "
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call
'LogInfo("Completed New()")
End Sub
'UserService overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
'LogInfo("In Dispose()")
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' The main entry point for the process
<MTAThread()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New
EmailPoller()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
Friend WithEvents EmailQueueTimer As System.Timers.Timer
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Friend WithEvents da_get_messages As
System.Data.SqlClient.SqlDataAdapter
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.EmailQueueTimer = New System.Timers.Timer()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
Me.da_get_messages = New System.Data.SqlClient.SqlDataAdapter()
Me.cmd_get_poller_settings = New System.Data.SqlClient.SqlCommand()
Me.cmd_update_msg = New System.Data.SqlClient.SqlCommand()
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
CType(Me.EmailQueueTimer,
System.ComponentModel.ISupportInitialize).BeginInit()
'LogInfo("Init EmailQueueTimer")
'
'EmailQueueTimer
'
Me.EmailQueueTimer.Enabled = True
Me.EmailQueueTimer.Interval = 10000
'
'LogInfo("Init SqlConnection1")
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=VENUS;initial
catalog=FTSolutions;password=web4pay;persist security i" & _
"nfo=True;user id=ftsweb;workstation id=PROGRAMMER1;packet
size=4096"
'
'da_get_messages
'
Me.da_get_messages.SelectCommand = Me.SqlSelectCommand1
'
'cmd_get_poller_settings
'
Me.cmd_get_poller_settings.CommandText =
"dbo.[COM_GET_EMAIL_QUEUE_SETTINGS_SP]"
Me.cmd_get_poller_settings.CommandType =
System.Data.CommandType.StoredProcedure
Me.cmd_get_poller_settings.Connection = Me.SqlConnection1
Me.cmd_get_poller_settings.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_msg.CommandText =
"dbo.[COM_UPDATE_EMAIL_QUEUE_MSG_STATUS_SP]"
Me.cmd_update_msg.CommandType =
System.Data.CommandType.StoredProcedure
Me.cmd_update_msg.Connection = Me.SqlConnection1
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@status", System.Data.SqlDbType.TinyInt,
1, System.Data.ParameterDirection.Input, False, CType(3, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@date_attempted",
System.Data.SqlDbType.DateTime, 8))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@error_message",
System.Data.SqlDbType.VarChar, 100))
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText =
"dbo.[COM_GET_EMAIL_QUEUE_MESSAGES_SP]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@quantity", System.Data.SqlDbType.Int,
4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.DataRowVersion.Current, Nothing))
'
'EmailPoller
'
Me.CanPauseAndContinue = True
Me.ServiceName = "EmailPoller"
CType(Me.EmailQueueTimer,
System.ComponentModel.ISupportInitialize).EndInit()
End Sub
#End Region
Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("EmailPoller Started")
EmailQueueTimer.Start()
End Sub
Protected Overrides Sub OnStop()
'LogInfo("EmailPoller Stopped")
EmailQueueTimer.Stop()
End Sub
Private Sub EmailQueueTimer_Elapsed(ByVal sender As System.Object, ByVal
e As System.Timers.ElapsedEventArgs) Handles EmailQueueTimer.Elapsed
'LogInfo("EmailPoller Timer Interval")
PollAndSendEmail()
End Sub
Private Sub PollAndSendEmail()
Try
'LogInfo("PollAndSend() Starting")
Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessages As
Integer
Dim DR As SqlDataReader
' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnection()
strProgress = "About to execute the reader"
***************************************************
Thanks,
Tom