473,748 Members | 10,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
ProjectInstalle r.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.ServiceP rocess
Imports System.Web.Mail
Imports System.Data.Sql Client
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.ServiceP rocess.ServiceB ase
Friend WithEvents cmd_get_poller_ settings As
System.Data.Sql Client.SqlComma nd
Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
'LogInfo("Compl eted 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

' The main entry point for the process
<MTAThread()_
Shared Sub Main()
Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase

' 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.ServiceP rocess.ServiceB ase () {New
Service1, New MySecondUserSer vice}
'
ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
EmailPoller()}

System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

' 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.T imer
Friend WithEvents SqlConnection1 As System.Data.Sql Client.SqlConne ction
Friend WithEvents da_get_messages As
System.Data.Sql Client.SqlDataA dapter
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
Me.EmailQueueTi mer = New System.Timers.T imer()
Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
Me.cmd_get_poll er_settings = New System.Data.Sql Client.SqlComma nd()
Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
CType(Me.EmailQ ueueTimer,
System.Componen tModel.ISupport Initialize).Beg inInit()

'LogInfo("Init EmailQueueTimer ")
'
'EmailQueueTime r
'
Me.EmailQueueTi mer.Enabled = True
Me.EmailQueueTi mer.Interval = 10000
'
'LogInfo("Init SqlConnection1" )
'SqlConnection1
'
Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
catalog=FTSolut ions;password=w eb4pay;persist security i" & _
"nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
size=4096"
'
'da_get_message s
'
Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
'
'cmd_get_poller _settings
'
Me.cmd_get_poll er_settings.Com mandText =
"dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
Me.cmd_get_poll er_settings.Com mandType =
System.Data.Com mandType.Stored Procedure
Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
Me.cmd_get_poll er_settings.Par ameters.Add(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_m sg.CommandText =
"dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
Me.cmd_update_m sg.CommandType =
System.Data.Com mandType.Stored Procedure
Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@status", System.Data.Sql DbType.TinyInt,
1, System.Data.Par ameterDirection .Input, False, CType(3, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@date_att empted",
System.Data.Sql DbType.DateTime , 8))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@error_me ssage",
System.Data.Sql DbType.VarChar, 100))
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt =
"dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.Com mandType.Stored Procedure
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@quantity ", System.Data.Sql DbType.Int,
4, System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
'
'EmailPoller
'
Me.CanPauseAndC ontinue = True
Me.ServiceName = "EmailPolle r"
CType(Me.EmailQ ueueTimer,
System.Componen tModel.ISupport Initialize).End Init()

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("Email Poller Started")
EmailQueueTimer .Start()
End Sub

Protected Overrides Sub OnStop()
'LogInfo("Email Poller Stopped")
EmailQueueTimer .Stop()
End Sub

Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object, ByVal
e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
'LogInfo("Email Poller Timer Interval")
PollAndSendEmai l()
End Sub

Private Sub PollAndSendEmai l()
Try
'LogInfo("PollA ndSend() Starting")

Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges As
Integer
Dim DR As SqlDataReader

' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnectio n()

strProgress = "About to execute the reader"

*************** *************** *************** ******

Thanks,

Tom
Jul 21 '06 #1
7 4659
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**********@f tsolutions.comw rote in message
news:e6******** ******@TK2MSFTN GP03.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
ProjectInstalle r.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.ServiceP rocess
Imports System.Web.Mail
Imports System.Data.Sql Client
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.ServiceP rocess.ServiceB ase
Friend WithEvents cmd_get_poller_ settings As
System.Data.Sql Client.SqlComma nd
Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
'LogInfo("Compl eted 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

' The main entry point for the process
<MTAThread()_
Shared Sub Main()
Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase

' 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.ServiceP rocess.ServiceB ase () {New
Service1, New MySecondUserSer vice}
'
ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
EmailPoller()}

System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

' 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.T imer
Friend WithEvents SqlConnection1 As System.Data.Sql Client.SqlConne ction
Friend WithEvents da_get_messages As
System.Data.Sql Client.SqlDataA dapter
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
Me.EmailQueueTi mer = New System.Timers.T imer()
Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
Me.cmd_get_poll er_settings = New System.Data.Sql Client.SqlComma nd()
Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
CType(Me.EmailQ ueueTimer,
System.Componen tModel.ISupport Initialize).Beg inInit()

'LogInfo("Init EmailQueueTimer ")
'
'EmailQueueTime r
'
Me.EmailQueueTi mer.Enabled = True
Me.EmailQueueTi mer.Interval = 10000
'
'LogInfo("Init SqlConnection1" )
'SqlConnection1
'
Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
catalog=FTSolut ions;password=w eb4pay;persist security i" & _
"nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
size=4096"
'
'da_get_message s
'
Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
'
'cmd_get_poller _settings
'
Me.cmd_get_poll er_settings.Com mandText =
"dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
Me.cmd_get_poll er_settings.Com mandType =
System.Data.Com mandType.Stored Procedure
Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
Me.cmd_get_poll er_settings.Par ameters.Add(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_m sg.CommandText =
"dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
Me.cmd_update_m sg.CommandType =
System.Data.Com mandType.Stored Procedure
Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@status",
System.Data.Sql DbType.TinyInt, 1, System.Data.Par ameterDirection .Input,
False, CType(3, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@date_att empted",
System.Data.Sql DbType.DateTime , 8))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sql Client.SqlParam eter("@error_me ssage",
System.Data.Sql DbType.VarChar, 100))
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt =
"dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.Com mandType.Stored Procedure
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@quantity ", System.Data.Sql DbType.Int,
4, System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
'
'EmailPoller
'
Me.CanPauseAndC ontinue = True
Me.ServiceName = "EmailPolle r"
CType(Me.EmailQ ueueTimer,
System.Componen tModel.ISupport Initialize).End Init()

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("Email Poller Started")
EmailQueueTimer .Start()
End Sub

Protected Overrides Sub OnStop()
'LogInfo("Email Poller Stopped")
EmailQueueTimer .Stop()
End Sub

Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
ByVal e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
'LogInfo("Email Poller Timer Interval")
PollAndSendEmai l()
End Sub

Private Sub PollAndSendEmai l()
Try
'LogInfo("PollA ndSend() Starting")

Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges As
Integer
Dim DR As SqlDataReader

' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnectio n()

strProgress = "About to execute the reader"

*************** *************** *************** ******

Thanks,

Tom

Jul 21 '06 #2
"SStory" <no****@nospam. comwrote in message
news:uD******** ******@TK2MSFTN GP02.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**********@f tsolutions.comw rote in message
news:e6******** ******@TK2MSFTN GP03.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
ProjectInstall er.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.ServiceP rocess
Imports System.Web.Mail
Imports System.Data.Sql Client
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.ServiceP rocess.ServiceB ase
Friend WithEvents cmd_get_poller_ settings As
System.Data.Sq lClient.SqlComm and
Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlSelectComman d1 As
System.Data.Sq lClient.SqlComm and
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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
'LogInfo("Compl eted 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

' The main entry point for the process
<MTAThread()_
Shared Sub Main()
Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase

' 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.ServiceP rocess.ServiceB ase () {New
Service1, New MySecondUserSer vice}
'
ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
EmailPoller( )}

System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

' 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.T imer
Friend WithEvents SqlConnection1 As
System.Data.Sq lClient.SqlConn ection
Friend WithEvents da_get_messages As
System.Data.Sq lClient.SqlData Adapter
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeComp onent()
Me.EmailQueueTi mer = New System.Timers.T imer()
Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
Me.cmd_get_poll er_settings = New
System.Data.Sq lClient.SqlComm and()
Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
CType(Me.EmailQ ueueTimer,
System.Compone ntModel.ISuppor tInitialize).Be ginInit()

'LogInfo("Init EmailQueueTimer ")
'
'EmailQueueTime r
'
Me.EmailQueueTi mer.Enabled = True
Me.EmailQueueTi mer.Interval = 10000
'
'LogInfo("Init SqlConnection1" )
'SqlConnection1
'
Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
catalog=FTSolu tions;password= web4pay;persist security i" & _
"nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
size=4096"
'
'da_get_message s
'
Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
'
'cmd_get_poller _settings
'
Me.cmd_get_poll er_settings.Com mandText =
"dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
Me.cmd_get_poll er_settings.Com mandType =
System.Data.Co mmandType.Store dProcedure
Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
Me.cmd_get_poll er_settings.Par ameters.Add(New
System.Data.Sq lClient.SqlPara meter("@RETURN_ VALUE",
System.Data.Sq lDbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Da taRowVersion.Cu rrent, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_m sg.CommandText =
"dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
Me.cmd_update_m sg.CommandType =
System.Data.Co mmandType.Store dProcedure
Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sq lClient.SqlPara meter("@RETURN_ VALUE",
System.Data.Sq lDbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Da taRowVersion.Cu rrent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sq lClient.SqlPara meter("@id", System.Data.Sql DbType.Int, 4,
System.Data.Pa rameterDirectio n.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sq lClient.SqlPara meter("@status" ,
System.Data.Sq lDbType.TinyInt , 1, System.Data.Par ameterDirection .Input,
False, CType(3, Byte), CType(0, Byte), "",
System.Data.Da taRowVersion.Cu rrent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sq lClient.SqlPara meter("@date_at tempted",
System.Data.Sq lDbType.DateTim e, 8))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.Sq lClient.SqlPara meter("@error_m essage",
System.Data.Sq lDbType.VarChar , 100))
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt =
"dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.Co mmandType.Store dProcedure
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sq lClient.SqlPara meter("@RETURN_ VALUE",
System.Data.Sq lDbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Da taRowVersion.Cu rrent, Nothing))
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sq lClient.SqlPara meter("@quantit y",
System.Data.Sq lDbType.Int, 4, System.Data.Par ameterDirection .Input,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.Da taRowVersion.Cu rrent, Nothing))
'
'EmailPoller
'
Me.CanPauseAndC ontinue = True
Me.ServiceName = "EmailPolle r"
CType(Me.EmailQ ueueTimer,
System.Compone ntModel.ISuppor tInitialize).En dInit()

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("Email Poller Started")
EmailQueueTimer .Start()
End Sub

Protected Overrides Sub OnStop()
'LogInfo("Email Poller Stopped")
EmailQueueTimer .Stop()
End Sub

Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
ByVal e As System.Timers.E lapsedEventArgs ) Handles
EmailQueueTime r.Elapsed
'LogInfo("Email Poller Timer Interval")
PollAndSendEmai l()
End Sub

Private Sub PollAndSendEmai l()
Try
'LogInfo("PollA ndSend() Starting")

Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges As
Integer
Dim DR As SqlDataReader

' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnectio n()

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
| ProjectInstalle r.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**********@f tsolutions.comw rote in message
news:e6******** ******@TK2MSFTN GP03.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
| ProjectInstalle r.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.ServiceP rocess
| Imports System.Web.Mail
| Imports System.Data.Sql Client
| 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.ServiceP rocess.ServiceB ase
| Friend WithEvents cmd_get_poller_ settings As
| System.Data.Sql Client.SqlComma nd
| Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
| Friend WithEvents SqlSelectComman d1 As System.Data.Sql Client.SqlComma nd
| 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.
| InitializeCompo nent()
|
| ' Add any initialization after the InitializeCompo nent() call
| 'LogInfo("Compl eted 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.Disp ose()
| End If
| End If
| MyBase.Dispose( disposing)
| End Sub
|
| ' The main entry point for the process
| <MTAThread()_
| Shared Sub Main()
| Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase
|
| ' 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.ServiceP rocess.ServiceB ase () {New
| Service1, New MySecondUserSer vice}
| '
| ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
| EmailPoller()}
|
| System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
| End Sub
|
| 'Required by the Component Designer
| Private components As System.Componen tModel.IContain er
|
| ' 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.T imer
| Friend WithEvents SqlConnection1 As System.Data.Sql Client.SqlConne ction
| Friend WithEvents da_get_messages As
| System.Data.Sql Client.SqlDataA dapter
| <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
| InitializeCompo nent()
| Me.EmailQueueTi mer = New System.Timers.T imer()
| Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
| Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
| Me.cmd_get_poll er_settings = New System.Data.Sql Client.SqlComma nd()
| Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
| Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
| CType(Me.EmailQ ueueTimer,
| System.Componen tModel.ISupport Initialize).Beg inInit()
|
| 'LogInfo("Init EmailQueueTimer ")
| '
| 'EmailQueueTime r
| '
| Me.EmailQueueTi mer.Enabled = True
| Me.EmailQueueTi mer.Interval = 10000
| '
| 'LogInfo("Init SqlConnection1" )
| 'SqlConnection1
| '
| Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
| catalog=FTSolut ions;password=w eb4pay;persist security i" & _
| "nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
| size=4096"
| '
| 'da_get_message s
| '
| Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
| '
| 'cmd_get_poller _settings
| '
| Me.cmd_get_poll er_settings.Com mandText =
| "dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
| Me.cmd_get_poll er_settings.Com mandType =
| System.Data.Com mandType.Stored Procedure
| Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
| Me.cmd_get_poll er_settings.Par ameters.Add(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| '
| 'cmd_update_msg
| '
| Me.cmd_update_m sg.CommandText =
| "dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
| Me.cmd_update_m sg.CommandType =
| System.Data.Com mandType.Stored Procedure
| Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@status",
System.Data.Sql DbType.TinyInt,
| 1, System.Data.Par ameterDirection .Input, False, CType(3, Byte), CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@date_att empted",
| System.Data.Sql DbType.DateTime , 8))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@error_me ssage",
| System.Data.Sql DbType.VarChar, 100))
| '
| 'SqlSelectComma nd1
| '
| Me.SqlSelectCom mand1.CommandTe xt =
| "dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
| Me.SqlSelectCom mand1.CommandTy pe =
| System.Data.Com mandType.Stored Procedure
| Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
| Me.SqlSelectCom mand1.Parameter s.Add(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4, System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.SqlSelectCom mand1.Parameter s.Add(New
| System.Data.Sql Client.SqlParam eter("@quantity ", System.Data.Sql DbType.Int,
| 4, System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| '
| 'EmailPoller
| '
| Me.CanPauseAndC ontinue = True
| Me.ServiceName = "EmailPolle r"
| CType(Me.EmailQ ueueTimer,
| System.Componen tModel.ISupport Initialize).End Init()
|
| End Sub
|
| #End Region
|
| Protected Overrides Sub OnStart(ByVal args() As String)
| 'LogInfo("Email Poller Started")
| EmailQueueTimer .Start()
| End Sub
|
| Protected Overrides Sub OnStop()
| 'LogInfo("Email Poller Stopped")
| EmailQueueTimer .Stop()
| End Sub
|
| Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
ByVal
| e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
| 'LogInfo("Email Poller Timer Interval")
| PollAndSendEmai l()
| End Sub
|
| Private Sub PollAndSendEmai l()
| Try
| 'LogInfo("PollA ndSend() Starting")
|
| Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
| Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges As
| Integer
| Dim DR As SqlDataReader
|
| ' grab our poller/email settings from DB
| strProgress = "About to open connection"
| dbOpenConnectio n()
|
| strProgress = "About to execute the reader"
|
| *************** *************** *************** ******
|
| Thanks,
|
| Tom
|
|
Jul 23 '06 #4
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.netw rote in
message news:%2******** ********@TK2MSF TNGP02.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
| ProjectInstalle r.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**********@f tsolutions.comw rote in message
news:e6******** ******@TK2MSFTN GP03.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
| ProjectInstalle r.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.ServiceP rocess
| Imports System.Web.Mail
| Imports System.Data.Sql Client
| 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.ServiceP rocess.ServiceB ase
| Friend WithEvents cmd_get_poller_ settings As
| System.Data.Sql Client.SqlComma nd
| Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
| Friend WithEvents SqlSelectComman d1 As
System.Data.Sql Client.SqlComma nd
| 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.
| InitializeCompo nent()
|
| ' Add any initialization after the InitializeCompo nent() call
| 'LogInfo("Compl eted 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.Disp ose()
| End If
| End If
| MyBase.Dispose( disposing)
| End Sub
|
| ' The main entry point for the process
| <MTAThread()_
| Shared Sub Main()
| Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase
|
| ' 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.ServiceP rocess.ServiceB ase () {New
| Service1, New MySecondUserSer vice}
| '
| ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
| EmailPoller()}
|
| System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
| End Sub
|
| 'Required by the Component Designer
| Private components As System.Componen tModel.IContain er
|
| ' 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.T imer
| Friend WithEvents SqlConnection1 As
System.Data.Sql Client.SqlConne ction
| Friend WithEvents da_get_messages As
| System.Data.Sql Client.SqlDataA dapter
| <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
| InitializeCompo nent()
| Me.EmailQueueTi mer = New System.Timers.T imer()
| Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
| Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
| Me.cmd_get_poll er_settings = New
System.Data.Sql Client.SqlComma nd()
| Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
| Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
| CType(Me.EmailQ ueueTimer,
| System.Componen tModel.ISupport Initialize).Beg inInit()
|
| 'LogInfo("Init EmailQueueTimer ")
| '
| 'EmailQueueTime r
| '
| Me.EmailQueueTi mer.Enabled = True
| Me.EmailQueueTi mer.Interval = 10000
| '
| 'LogInfo("Init SqlConnection1" )
| 'SqlConnection1
| '
| Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
| catalog=FTSolut ions;password=w eb4pay;persist security i" & _
| "nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
| size=4096"
| '
| 'da_get_message s
| '
| Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
| '
| 'cmd_get_poller _settings
| '
| Me.cmd_get_poll er_settings.Com mandText =
| "dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
| Me.cmd_get_poll er_settings.Com mandType =
| System.Data.Com mandType.Stored Procedure
| Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
| Me.cmd_get_poll er_settings.Par ameters.Add(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| '
| 'cmd_update_msg
| '
| Me.cmd_update_m sg.CommandText =
| "dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
| Me.cmd_update_m sg.CommandType =
| System.Data.Com mandType.Stored Procedure
| Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@status",
System.Data.Sql DbType.TinyInt,
| 1, System.Data.Par ameterDirection .Input, False, CType(3, Byte), CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@date_att empted",
| System.Data.Sql DbType.DateTime , 8))
| Me.cmd_update_m sg.Parameters.A dd(New
| System.Data.Sql Client.SqlParam eter("@error_me ssage",
| System.Data.Sql DbType.VarChar, 100))
| '
| 'SqlSelectComma nd1
| '
| Me.SqlSelectCom mand1.CommandTe xt =
| "dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
| Me.SqlSelectCom mand1.CommandTy pe =
| System.Data.Com mandType.Stored Procedure
| Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
| Me.SqlSelectCom mand1.Parameter s.Add(New
| System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .ReturnValue,
| False, CType(10, Byte), CType(0, Byte), "",
| System.Data.Dat aRowVersion.Cur rent, Nothing))
| Me.SqlSelectCom mand1.Parameter s.Add(New
| System.Data.Sql Client.SqlParam eter("@quantity ",
System.Data.Sql DbType.Int,
| 4, System.Data.Par ameterDirection .Input, False, CType(10, Byte),
CType(0,
| Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| '
| 'EmailPoller
| '
| Me.CanPauseAndC ontinue = True
| Me.ServiceName = "EmailPolle r"
| CType(Me.EmailQ ueueTimer,
| System.Componen tModel.ISupport Initialize).End Init()
|
| End Sub
|
| #End Region
|
| Protected Overrides Sub OnStart(ByVal args() As String)
| 'LogInfo("Email Poller Started")
| EmailQueueTimer .Start()
| End Sub
|
| Protected Overrides Sub OnStop()
| 'LogInfo("Email Poller Stopped")
| EmailQueueTimer .Stop()
| End Sub
|
| Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
ByVal
| e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
| 'LogInfo("Email Poller Timer Interval")
| PollAndSendEmai l()
| End Sub
|
| Private Sub PollAndSendEmai l()
| Try
| 'LogInfo("PollA ndSend() Starting")
|
| Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
| Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges
As
| Integer
| Dim DR As SqlDataReader
|
| ' grab our poller/email settings from DB
| strProgress = "About to open connection"
| dbOpenConnectio n()
|
| 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******** ******@TK2MSFTN GP04.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.netw rote in
| message news:%2******** ********@TK2MSF TNGP02.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
| | ProjectInstalle r.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**********@f tsolutions.comw rote in message
| news:e6******** ******@TK2MSFTN GP03.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
| | ProjectInstalle r.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.ServiceP rocess
| | Imports System.Web.Mail
| | Imports System.Data.Sql Client
| | 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.ServiceP rocess.ServiceB ase
| | Friend WithEvents cmd_get_poller_ settings As
| | System.Data.Sql Client.SqlComma nd
| | Friend WithEvents cmd_update_msg As
System.Data.Sql Client.SqlComma nd
| | Friend WithEvents SqlSelectComman d1 As
| System.Data.Sql Client.SqlComma nd
| | 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.
| | InitializeCompo nent()
| |
| | ' Add any initialization after the InitializeCompo nent() call
| | 'LogInfo("Compl eted 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.Disp ose()
| | End If
| | End If
| | MyBase.Dispose( disposing)
| | End Sub
| |
| | ' The main entry point for the process
| | <MTAThread()_
| | Shared Sub Main()
| | Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase
| |
| | ' 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.ServiceP rocess.ServiceB ase ()
{New
| | Service1, New MySecondUserSer vice}
| | '
| | ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
| | EmailPoller()}
| |
| | System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
| | End Sub
| |
| | 'Required by the Component Designer
| | Private components As System.Componen tModel.IContain er
| |
| | ' 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.T imer
| | Friend WithEvents SqlConnection1 As
| System.Data.Sql Client.SqlConne ction
| | Friend WithEvents da_get_messages As
| | System.Data.Sql Client.SqlDataA dapter
| | <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
| | InitializeCompo nent()
| | Me.EmailQueueTi mer = New System.Timers.T imer()
| | Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
| | Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
| | Me.cmd_get_poll er_settings = New
| System.Data.Sql Client.SqlComma nd()
| | Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
| | Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
| | CType(Me.EmailQ ueueTimer,
| | System.Componen tModel.ISupport Initialize).Beg inInit()
| |
| | 'LogInfo("Init EmailQueueTimer ")
| | '
| | 'EmailQueueTime r
| | '
| | Me.EmailQueueTi mer.Enabled = True
| | Me.EmailQueueTi mer.Interval = 10000
| | '
| | 'LogInfo("Init SqlConnection1" )
| | 'SqlConnection1
| | '
| | Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
| | catalog=FTSolut ions;password=w eb4pay;persist security i" & _
| | "nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
| | size=4096"
| | '
| | 'da_get_message s
| | '
| | Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
| | '
| | 'cmd_get_poller _settings
| | '
| | Me.cmd_get_poll er_settings.Com mandText =
| | "dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
| | Me.cmd_get_poll er_settings.Com mandType =
| | System.Data.Com mandType.Stored Procedure
| | Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
| | Me.cmd_get_poll er_settings.Par ameters.Add(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | '
| | 'cmd_update_msg
| | '
| | Me.cmd_update_m sg.CommandText =
| | "dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
| | Me.cmd_update_m sg.CommandType =
| | System.Data.Com mandType.Stored Procedure
| | Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int,
4,
| | System.Data.Par ameterDirection .Input, False, CType(10, Byte), CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@status",
| System.Data.Sql DbType.TinyInt,
| | 1, System.Data.Par ameterDirection .Input, False, CType(3, Byte),
CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@date_att empted",
| | System.Data.Sql DbType.DateTime , 8))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@error_me ssage",
| | System.Data.Sql DbType.VarChar, 100))
| | '
| | 'SqlSelectComma nd1
| | '
| | Me.SqlSelectCom mand1.CommandTe xt =
| | "dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
| | Me.SqlSelectCom mand1.CommandTy pe =
| | System.Data.Com mandType.Stored Procedure
| | Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
| | Me.SqlSelectCom mand1.Parameter s.Add(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.SqlSelectCom mand1.Parameter s.Add(New
| | System.Data.Sql Client.SqlParam eter("@quantity ",
| System.Data.Sql DbType.Int,
| | 4, System.Data.Par ameterDirection .Input, False, CType(10, Byte),
| CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | '
| | 'EmailPoller
| | '
| | Me.CanPauseAndC ontinue = True
| | Me.ServiceName = "EmailPolle r"
| | CType(Me.EmailQ ueueTimer,
| | System.Componen tModel.ISupport Initialize).End Init()
| |
| | End Sub
| |
| | #End Region
| |
| | Protected Overrides Sub OnStart(ByVal args() As String)
| | 'LogInfo("Email Poller Started")
| | EmailQueueTimer .Start()
| | End Sub
| |
| | Protected Overrides Sub OnStop()
| | 'LogInfo("Email Poller Stopped")
| | EmailQueueTimer .Stop()
| | End Sub
| |
| | Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
| ByVal
| | e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
| | 'LogInfo("Email Poller Timer Interval")
| | PollAndSendEmai l()
| | End Sub
| |
| | Private Sub PollAndSendEmai l()
| | Try
| | 'LogInfo("PollA ndSend() Starting")
| |
| | Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
| | Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges
| As
| | Integer
| | Dim DR As SqlDataReader
| |
| | ' grab our poller/email settings from DB
| | strProgress = "About to open connection"
| | dbOpenConnectio n()
| |
| | 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**********@f tsolutions.comw rote in message
news:OG******** ******@TK2MSFTN GP04.phx.gbl...
"SStory" <no****@nospam. comwrote in message
news:uD******** ******@TK2MSFTN GP02.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**********@f tsolutions.comw rote in message
news:e6******* *******@TK2MSFT NGP03.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:

CMailMessag e
EmailPoller (the offending Class)
Project Installer.

There are 2 files:

EmailPoller.v b
ProjectInstal ler.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.ServiceP rocess
Imports System.Web.Mail
Imports System.Data.Sql Client
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.ServiceP rocess.ServiceB ase
Friend WithEvents cmd_get_poller_ settings As
System.Data.S qlClient.SqlCom mand
Friend WithEvents cmd_update_msg As System.Data.Sql Client.SqlComma nd
Friend WithEvents SqlSelectComman d1 As
System.Data.S qlClient.SqlCom mand
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.
InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call
'LogInfo("Compl eted 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

' The main entry point for the process
<MTAThread()_
Shared Sub Main()
Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase

' 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.ServiceP rocess.ServiceB ase () {New
Service1, New MySecondUserSer vice}
'
ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
EmailPoller() }

System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

' 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.T imer
Friend WithEvents SqlConnection1 As
System.Data.S qlClient.SqlCon nection
Friend WithEvents da_get_messages As
System.Data.S qlClient.SqlDat aAdapter
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCom ponent()
Me.EmailQueueTi mer = New System.Timers.T imer()
Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
Me.da_get_messa ges = New System.Data.Sql Client.SqlDataA dapter()
Me.cmd_get_poll er_settings = New
System.Data.S qlClient.SqlCom mand()
Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
CType(Me.EmailQ ueueTimer,
System.Compon entModel.ISuppo rtInitialize).B eginInit()

'LogInfo("Init EmailQueueTimer ")
'
'EmailQueueTime r
'
Me.EmailQueueTi mer.Enabled = True
Me.EmailQueueTi mer.Interval = 10000
'
'LogInfo("Init SqlConnection1" )
'SqlConnection1
'
Me.SqlConnectio n1.ConnectionSt ring = "data source=VENUS;in itial
catalog=FTSol utions;password =web4pay;persis t security i" & _
"nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
size=4096"
'
'da_get_message s
'
Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
'
'cmd_get_poller _settings
'
Me.cmd_get_poll er_settings.Com mandText =
"dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
Me.cmd_get_poll er_settings.Com mandType =
System.Data.C ommandType.Stor edProcedure
Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
Me.cmd_get_poll er_settings.Par ameters.Add(New
System.Data.S qlClient.SqlPar ameter("@RETURN _VALUE",
System.Data.S qlDbType.Int, 4,
System.Data.P arameterDirecti on.ReturnValue, False, CType(10, Byte),
CType(0, Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
'
'cmd_update_msg
'
Me.cmd_update_m sg.CommandText =
"dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
Me.cmd_update_m sg.CommandType =
System.Data.C ommandType.Stor edProcedure
Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.S qlClient.SqlPar ameter("@RETURN _VALUE",
System.Data.S qlDbType.Int, 4,
System.Data.P arameterDirecti on.ReturnValue, False, CType(10, Byte),
CType(0, Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.S qlClient.SqlPar ameter("@id", System.Data.Sql DbType.Int, 4,
System.Data.P arameterDirecti on.Input, False, CType(10, Byte), CType(0,
Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.S qlClient.SqlPar ameter("@status ",
System.Data.S qlDbType.TinyIn t, 1, System.Data.Par ameterDirection .Input,
False, CType(3, Byte), CType(0, Byte), "",
System.Data.D ataRowVersion.C urrent, Nothing))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.S qlClient.SqlPar ameter("@date_a ttempted",
System.Data.S qlDbType.DateTi me, 8))
Me.cmd_update_m sg.Parameters.A dd(New
System.Data.S qlClient.SqlPar ameter("@error_ message",
System.Data.S qlDbType.VarCha r, 100))
'
'SqlSelectComma nd1
'
Me.SqlSelectCom mand1.CommandTe xt =
"dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.C ommandType.Stor edProcedure
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.S qlClient.SqlPar ameter("@RETURN _VALUE",
System.Data.S qlDbType.Int, 4,
System.Data.P arameterDirecti on.ReturnValue, False, CType(10, Byte),
CType(0, Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.S qlClient.SqlPar ameter("@quanti ty",
System.Data.S qlDbType.Int, 4, System.Data.Par ameterDirection .Input,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.D ataRowVersion.C urrent, Nothing))
'
'EmailPoller
'
Me.CanPauseAndC ontinue = True
Me.ServiceName = "EmailPolle r"
CType(Me.EmailQ ueueTimer,
System.Compon entModel.ISuppo rtInitialize).E ndInit()

End Sub

#End Region

Protected Overrides Sub OnStart(ByVal args() As String)
'LogInfo("Email Poller Started")
EmailQueueTimer .Start()
End Sub

Protected Overrides Sub OnStop()
'LogInfo("Email Poller Stopped")
EmailQueueTimer .Stop()
End Sub

Private Sub EmailQueueTimer _Elapsed(ByVal sender As System.Object,
ByVal e As System.Timers.E lapsedEventArgs ) Handles
EmailQueueTim er.Elapsed
'LogInfo("Email Poller Timer Interval")
PollAndSendEmai l()
End Sub

Private Sub PollAndSendEmai l()
Try
'LogInfo("PollA ndSend() Starting")

Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
Dim isHTML, intInterval, intMsgQuantity, intProcessMessa ges
As Integer
Dim DR As SqlDataReader

' grab our poller/email settings from DB
strProgress = "About to open connection"
dbOpenConnectio n()

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.netw rote in
message news:ez******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP04.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.netw rote in
| message news:%2******** ********@TK2MSF TNGP02.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
| | ProjectInstalle r.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**********@f tsolutions.comw rote in message
| news:e6******** ******@TK2MSFTN GP03.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
| | ProjectInstalle r.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.ServiceP rocess
| | Imports System.Web.Mail
| | Imports System.Data.Sql Client
| | 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.ServiceP rocess.ServiceB ase
| | Friend WithEvents cmd_get_poller_ settings As
| | System.Data.Sql Client.SqlComma nd
| | Friend WithEvents cmd_update_msg As
System.Data.Sql Client.SqlComma nd
| | Friend WithEvents SqlSelectComman d1 As
| System.Data.Sql Client.SqlComma nd
| | 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.
| | InitializeCompo nent()
| |
| | ' Add any initialization after the InitializeCompo nent() call
| | 'LogInfo("Compl eted 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.Disp ose()
| | End If
| | End If
| | MyBase.Dispose( disposing)
| | End Sub
| |
| | ' The main entry point for the process
| | <MTAThread()_
| | Shared Sub Main()
| | Dim ServicesToRun() As System.ServiceP rocess.ServiceB ase
| |
| | ' 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.ServiceP rocess.ServiceB ase ()
{New
| | Service1, New MySecondUserSer vice}
| | '
| | ServicesToRun = New System.ServiceP rocess.ServiceB ase() {New
| | EmailPoller()}
| |
| | System.ServiceP rocess.ServiceB ase.Run(Service sToRun)
| | End Sub
| |
| | 'Required by the Component Designer
| | Private components As System.Componen tModel.IContain er
| |
| | ' 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.T imer
| | Friend WithEvents SqlConnection1 As
| System.Data.Sql Client.SqlConne ction
| | Friend WithEvents da_get_messages As
| | System.Data.Sql Client.SqlDataA dapter
| | <System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
| | InitializeCompo nent()
| | Me.EmailQueueTi mer = New System.Timers.T imer()
| | Me.SqlConnectio n1 = New System.Data.Sql Client.SqlConne ction()
| | Me.da_get_messa ges = New
System.Data.Sql Client.SqlDataA dapter()
| | Me.cmd_get_poll er_settings = New
| System.Data.Sql Client.SqlComma nd()
| | Me.cmd_update_m sg = New System.Data.Sql Client.SqlComma nd()
| | Me.SqlSelectCom mand1 = New System.Data.Sql Client.SqlComma nd()
| | CType(Me.EmailQ ueueTimer,
| | System.Componen tModel.ISupport Initialize).Beg inInit()
| |
| | 'LogInfo("Init EmailQueueTimer ")
| | '
| | 'EmailQueueTime r
| | '
| | Me.EmailQueueTi mer.Enabled = True
| | Me.EmailQueueTi mer.Interval = 10000
| | '
| | 'LogInfo("Init SqlConnection1" )
| | 'SqlConnection1
| | '
| | Me.SqlConnectio n1.ConnectionSt ring = "data
source=VENUS;in itial
| | catalog=FTSolut ions;password=w eb4pay;persist security i" & _
| | "nfo=True;u ser id=ftsweb;works tation id=PROGRAMMER1; packet
| | size=4096"
| | '
| | 'da_get_message s
| | '
| | Me.da_get_messa ges.SelectComma nd = Me.SqlSelectCom mand1
| | '
| | 'cmd_get_poller _settings
| | '
| | Me.cmd_get_poll er_settings.Com mandText =
| | "dbo.[COM_GET_EMAIL_Q UEUE_SETTINGS_S P]"
| | Me.cmd_get_poll er_settings.Com mandType =
| | System.Data.Com mandType.Stored Procedure
| | Me.cmd_get_poll er_settings.Con nection = Me.SqlConnectio n1
| | Me.cmd_get_poll er_settings.Par ameters.Add(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | '
| | 'cmd_update_msg
| | '
| | Me.cmd_update_m sg.CommandText =
| | "dbo.[COM_UPDATE_EMAI L_QUEUE_MSG_STA TUS_SP]"
| | Me.cmd_update_m sg.CommandType =
| | System.Data.Com mandType.Stored Procedure
| | Me.cmd_update_m sg.Connection = Me.SqlConnectio n1
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@id", System.Data.Sql DbType.Int,
4,
| | System.Data.Par ameterDirection .Input, False, CType(10, Byte),
CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@status",
| System.Data.Sql DbType.TinyInt,
| | 1, System.Data.Par ameterDirection .Input, False, CType(3, Byte),
CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@date_att empted",
| | System.Data.Sql DbType.DateTime , 8))
| | Me.cmd_update_m sg.Parameters.A dd(New
| | System.Data.Sql Client.SqlParam eter("@error_me ssage",
| | System.Data.Sql DbType.VarChar, 100))
| | '
| | 'SqlSelectComma nd1
| | '
| | Me.SqlSelectCom mand1.CommandTe xt =
| | "dbo.[COM_GET_EMAIL_Q UEUE_MESSAGES_S P]"
| | Me.SqlSelectCom mand1.CommandTy pe =
| | System.Data.Com mandType.Stored Procedure
| | Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
| | Me.SqlSelectCom mand1.Parameter s.Add(New
| | System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
| | System.Data.Sql DbType.Int, 4,
| System.Data.Par ameterDirection .ReturnValue,
| | False, CType(10, Byte), CType(0, Byte), "",
| | System.Data.Dat aRowVersion.Cur rent, Nothing))
| | Me.SqlSelectCom mand1.Parameter s.Add(New
| | System.Data.Sql Client.SqlParam eter("@quantity ",
| System.Data.Sql DbType.Int,
| | 4, System.Data.Par ameterDirection .Input, False, CType(10, Byte),
| CType(0,
| | Byte), "", System.Data.Dat aRowVersion.Cur rent, Nothing))
| | '
| | 'EmailPoller
| | '
| | Me.CanPauseAndC ontinue = True
| | Me.ServiceName = "EmailPolle r"
| | CType(Me.EmailQ ueueTimer,
| | System.Componen tModel.ISupport Initialize).End Init()
| |
| | End Sub
| |
| | #End Region
| |
| | Protected Overrides Sub OnStart(ByVal args() As String)
| | 'LogInfo("Email Poller Started")
| | EmailQueueTimer .Start()
| | End Sub
| |
| | Protected Overrides Sub OnStop()
| | 'LogInfo("Email Poller Stopped")
| | EmailQueueTimer .Stop()
| | End Sub
| |
| | Private Sub EmailQueueTimer _Elapsed(ByVal sender As
System.Object,
| ByVal
| | e As System.Timers.E lapsedEventArgs ) Handles EmailQueueTimer .Elapsed
| | 'LogInfo("Email Poller Timer Interval")
| | PollAndSendEmai l()
| | End Sub
| |
| | Private Sub PollAndSendEmai l()
| | Try
| | 'LogInfo("PollA ndSend() Starting")
| |
| | Dim strSMTPServer, strSMTPUserID, strSMTPPwd As String
| | Dim isHTML, intInterval, intMsgQuantity,
intProcessMessa ges
| As
| | Integer
| | Dim DR As SqlDataReader
| |
| | ' grab our poller/email settings from DB
| | strProgress = "About to open connection"
| | dbOpenConnectio n()
| |
| | 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
2312
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 get comments about coding style. I'm especially unsure about how a class should be documented, what to put in, and where. When to use double quotes, and when single. For instance, the doc string at the top must be in double quotes, or else the...
4
30482
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
1705
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 release, and my first attempt at Python coding. Any comments, suggestions, pointers on using more common Python idioms or example coding snippets, etc, welcome! Thanks!
19
2208
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 by myself. Recently we have had .NET 1.1 then 2.0 installed and have been told to use it. After reading the books about it, and trying it for a couple of months, I got so mad I decided to write down all of my issues and rants and post them here....
4
9369
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 test instance as first argument (got test instance instead)" Below is the sample code (test) for this purpose (two files). Any help is greatly appreciated.
1
5062
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 with the ADSI NT Provider and only supported in the LDAP Provider. So given an UserId (UID) how can I read the First Name and Last Name using LDAP Provider. If anybody can help me with a C# sample code it would of great help. Thanks in advance.
7
1277
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 namespace name 'mylabel' could not be found (are you missing a using directive or an assembly reference?) and it has a wiggly line under it. I have saved the aspx file, but cant get the .cs file to recognise it. What comes first? Or what am I missing? I...
1
2634
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 mode. There is only one class in the file, the user control. The first line is "Namespace MyStuff". When I remove this line, all is well and I can view the control in Design mode.
4
5705
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 = new RijndaelManaged(); cipher.KeySize = 256; cipher.BlockSize = 256;
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.