473,385 Members | 1,597 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,385 software developers and data experts.

Not first class in file

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(ServicesToRu n)
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).BeginIni t()

'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_attempte d",
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
Jul 21 '06 #1
7 4630
I've had to do it for a form before.

I imagine anything MS does expects to be first as they don't usually
consider anyone else.

NEVER put a class above the form class definition. Probably holds true in a
service as well.

HTH,

Shane
"tshad" <ts**********@ftsolutions.comwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
>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(ServicesToRu n)
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).BeginIni t()

'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_attempte d",
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

Jul 21 '06 #2
"SStory" <no****@nospam.comwrote in message
news:uD**************@TK2MSFTNGP02.phx.gbl...
I've had to do it for a form before.

I imagine anything MS does expects to be first as they don't usually
consider anyone else.

NEVER put a class above the form class definition. Probably holds true in
a service as well.
How do you tell if this is a form class definition?

Tom
>
HTH,

Shane
"tshad" <ts**********@ftsolutions.comwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
>>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(ServicesToRu n)
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).BeginIn it()

'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_attempt ed",
System.Data.SqlDbType.DateTime, 8))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@error_messag e",
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


Jul 21 '06 #3
Tom,
I find its "Better" to have each type have its own file. Naming each file
for what it contains. As its then immediately obvious what's in the file by
looking at the file name. Plus you avoid this warning message.

So if you have 3 types (classes):
| CMailMessage
| EmailPoller (the offending Class)
| Project Installer.

You would have 3 files:|
| EmailPoller.vb
| ProjectInstaller.vb (which is created automatically).
CMailMessage.vb
As the message implies, the "designers" in VS expect the class to be first
type in a file... The Windows Service has a designer as it (EmailPoller)
inherits from ServiceBase which inherits from Component. Component has a
designer associated with it.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"tshad" <ts**********@ftsolutions.comwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
|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(ServicesToRu n)
| 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).BeginIni t()
|
| '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_attempte d",
| 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
|
|
Jul 23 '06 #4
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
message news:%2****************@TK2MSFTNGP02.phx.gbl...
Tom,
I find its "Better" to have each type have its own file. Naming each file
for what it contains. As its then immediately obvious what's in the file
by
looking at the file name. Plus you avoid this warning message.

So if you have 3 types (classes):
| CMailMessage
| EmailPoller (the offending Class)
| Project Installer.

You would have 3 files:|
| EmailPoller.vb
| ProjectInstaller.vb (which is created automatically).
CMailMessage.vb
As the message implies, the "designers" in VS expect the class to be first
type in a file... The Windows Service has a designer as it (EmailPoller)
inherits from ServiceBase which inherits from Component. Component has a
designer associated with it.
But why does it work OK in 2002 but not in 2003?

Tom
>
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"tshad" <ts**********@ftsolutions.comwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
|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(ServicesToRu n)
| 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).BeginIni t()
|
| '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_attempte d",
| 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
|
|


Jul 24 '06 #5
Tom,
| But why does it work OK in 2002 but not in 2003?
I understand MS fixed a bug that was (occasionally) being caused by having 2
classes in a single file.

Something about not being able to *accurately* identify which class was
actually being designed, I seem to remember it would always attempt to
design the first class...

It may work for you as CMailMessage is not designable.

Although it may have worked in 2002, as I stated, I find its cleaner
("better"), even in 2002, to keep individual types in individual files.
Where each file's name matches the type within that file. The "problem" is
when you overload a type with generic parameters, such as System.Nullable &
System.Nullable(Of T). What does one call the files for those two types?

One place where I may, *maybe*, put a type in with other types is Delegates.
Because a Delegate tends to be a single line, does it really make sense to
put it in its own file, especially when the Delegate is normally closely
tied to another type. Either a callback for a specific method, or an
EventHandler for a specific event? Of course with event handlers I normally
forgo defining a delegate in favor of using EventHandler(Of T).

http://msdn2.microsoft.com/en-us/library/db0etb8x.aspx

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"tshad" <tf*@dslextreme.comwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
| message news:%2****************@TK2MSFTNGP02.phx.gbl...
| Tom,
| I find its "Better" to have each type have its own file. Naming each
file
| for what it contains. As its then immediately obvious what's in the file
| by
| looking at the file name. Plus you avoid this warning message.
| >
| So if you have 3 types (classes):
| | CMailMessage
| | EmailPoller (the offending Class)
| | Project Installer.
| >
| You would have 3 files:|
| | EmailPoller.vb
| | ProjectInstaller.vb (which is created automatically).
| CMailMessage.vb
| >
| >
| As the message implies, the "designers" in VS expect the class to be
first
| type in a file... The Windows Service has a designer as it (EmailPoller)
| inherits from ServiceBase which inherits from Component. Component has a
| designer associated with it.
|
| But why does it work OK in 2002 but not in 2003?
|
| Tom
|
| >
| --
| Hope this helps
| Jay B. Harlow [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
| >
| >
| "tshad" <ts**********@ftsolutions.comwrote in message
| news:e6**************@TK2MSFTNGP03.phx.gbl...
| |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(ServicesToRu n)
| | 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).BeginIni t()
| |
| | '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_attempte d",
| | 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
| |
| |
| >
| >
|
|
Jul 24 '06 #6
Well it probably isn't If it were it would inherit from something like

system.form (don't remember off the top of my head).

But since you said it is a service, it might be following the same
methodology.

Basically, if you include an additional class inside of an MS generated
class file, be sure it is at the bottom of the file and the issue won't
matter.

"tshad" <ts**********@ftsolutions.comwrote in message
news:OG**************@TK2MSFTNGP04.phx.gbl...
"SStory" <no****@nospam.comwrote in message
news:uD**************@TK2MSFTNGP02.phx.gbl...
>I've had to do it for a form before.

I imagine anything MS does expects to be first as they don't usually
consider anyone else.

NEVER put a class above the form class definition. Probably holds true
in a service as well.

How do you tell if this is a form class definition?

Tom
>>
HTH,

Shane
"tshad" <ts**********@ftsolutions.comwrote in message
news:e6**************@TK2MSFTNGP03.phx.gbl...
>>>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(ServicesToRu n)
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).BeginI nit()

'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_VALU E",
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_VALU E",
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_attemp ted",
System.Data.SqlDbType.DateTime, 8))
Me.cmd_update_msg.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@error_messa ge",
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_VALU E",
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).EndIni t()

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



Jul 24 '06 #7
I mostly agree with Jay on this point.
I was just trying to tell you why you were getting the error and how to
avoid it.

I have placed simple classes that inherit from ListView at the bottom of a
form file that uses it. Whether this is best practice or not is a matter of
debate.

-Shane

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
message news:ez**************@TK2MSFTNGP03.phx.gbl...
Tom,
| But why does it work OK in 2002 but not in 2003?
I understand MS fixed a bug that was (occasionally) being caused by having
2
classes in a single file.

Something about not being able to *accurately* identify which class was
actually being designed, I seem to remember it would always attempt to
design the first class...

It may work for you as CMailMessage is not designable.

Although it may have worked in 2002, as I stated, I find its cleaner
("better"), even in 2002, to keep individual types in individual files.
Where each file's name matches the type within that file. The "problem" is
when you overload a type with generic parameters, such as System.Nullable
&
System.Nullable(Of T). What does one call the files for those two types?

One place where I may, *maybe*, put a type in with other types is
Delegates.
Because a Delegate tends to be a single line, does it really make sense to
put it in its own file, especially when the Delegate is normally closely
tied to another type. Either a callback for a specific method, or an
EventHandler for a specific event? Of course with event handlers I
normally
forgo defining a delegate in favor of using EventHandler(Of T).

http://msdn2.microsoft.com/en-us/library/db0etb8x.aspx

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"tshad" <tf*@dslextreme.comwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
| message news:%2****************@TK2MSFTNGP02.phx.gbl...
| Tom,
| I find its "Better" to have each type have its own file. Naming each
file
| for what it contains. As its then immediately obvious what's in the
file
| by
| looking at the file name. Plus you avoid this warning message.
| >
| So if you have 3 types (classes):
| | CMailMessage
| | EmailPoller (the offending Class)
| | Project Installer.
| >
| You would have 3 files:|
| | EmailPoller.vb
| | ProjectInstaller.vb (which is created automatically).
| CMailMessage.vb
| >
| >
| As the message implies, the "designers" in VS expect the class to be
first
| type in a file... The Windows Service has a designer as it
(EmailPoller)
| inherits from ServiceBase which inherits from Component. Component has
a
| designer associated with it.
|
| But why does it work OK in 2002 but not in 2003?
|
| Tom
|
| >
| --
| Hope this helps
| Jay B. Harlow [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
| >
| >
| "tshad" <ts**********@ftsolutions.comwrote in message
| news:e6**************@TK2MSFTNGP03.phx.gbl...
| |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(ServicesToRu n)
| | 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).BeginIni t()
| |
| | '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_attempte d",
| | 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
| |
| |
| >
| >
|
|


Jul 24 '06 #8

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

Similar topics

6
by: Peter Kleiweg | last post by:
I'm still new to Python. All my experience with OO programming is in a distant past with C++. Now I have written my first class in Python. The class behaves exactly as I want, but I would like to...
4
by: Tor Erik Sønvisen | last post by:
Hi How can I read the first line of a file and then delete this line, so that line 2 is line 1 on next read? regards
1
by: avinashc | last post by:
If anyone is interested in a /etc/hosts.deny automatic update script (Unix only) based on sshd/vsftpd attacks, here's a python script: http://www.aczoom.com/tools/blockhosts/ This is a beta...
19
by: DotNetIsHorrible | last post by:
I write CRUD database applications for a living for an audience of about 100 users per application using classic ASP. I maintain and frequently change on user's request 22 different applications...
4
by: arotem | last post by:
Hi, I am trying to call an unbound method (PrintInput) with the object instance as the first argument but getting the following error: "TypeError: unbound method PrintInput() must be called with...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
7
by: louise raisbeck | last post by:
Hi, i am using code behind c# pages. I have put a couple of asp:labels on the aspx html page. in the code behind i am trying to set them programatically but am getting error The type or...
1
by: qwert | last post by:
Hello, when creating a user control with Visual Basic .NET (v2.0), I get the error: "Visual Studio requires that designers use the first class the the file." when I try it view it in Design...
4
by: Fritjolf | last post by:
Hi. I've got a strange problem... I've made a simple program to test encryption/decryption. I use Rijndael encryption and here are the most important properties. RijndaelManaged cipher =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.