469,625 Members | 1,137 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

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 4445
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Peter Kleiweg | last post: by
4 posts views Thread by Tor Erik Sønvisen | last post: by
19 posts views Thread by DotNetIsHorrible | last post: by
7 posts views Thread by louise raisbeck | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.