G
Guest
Hi Guys,
I writing a project with just one module in it (the reason for this is to
debug code before it becomes a service) and am getting an error which I do
not understand:
No accessible 'Main' method with an appropriate signature was found in
'FTP_Log_Watcher'.
I have set the properties of FTP_Log_Watcher to Startup with 'Sub Main'.
I used to use VB6 about 3-4 years ago, but only as an amatuer. I have only
been using Visual Basic for 2 months - please go easy if it is obvious to you.
Below is the module:
Imports System.IO
Imports System.Data
Public Class EDI_Watcher
Dim gSQLCommandBuilder As System.Data.SqlClient.SqlCommandBuilder
Dim gDataAdapter As System.Data.SqlClient.SqlDataAdapter
Dim gCurrentExample As Integer
Private sDatabase As String
Private sServer As String
Private sUserID As String
Private sPassword As String
Private sConnectionString As String
Private cnn As System.Data.SqlClient.SqlConnection
Private cmd As System.Data.SqlClient.SqlCommand
Public WriteOnly Property Database()
Set(ByVal Value)
sDatabase = Value
End Set
End Property
Public WriteOnly Property Server()
Set(ByVal Value)
sServer = Value
End Set
End Property
Public WriteOnly Property UserID()
Set(ByVal Value)
sUserID = Value
End Set
End Property
Public WriteOnly Property Password()
Set(ByVal Value)
sPassword = Value
End Set
End Property
Public Sub Main(ByVal args() As String)
Call Watcher()
End Sub
Public Sub Watcher()
Const ForReading = 1, ForWriting = 2
Dim MyFileObject
Dim ScriptTimeout
Dim DebugFlag As Boolean
Dim MyFolder
Dim SubFolder
Dim Folder
Dim Date_Comps
Dim Log_Dir
Dim CurrentFolder
Dim FileColl
Dim objFile
Dim strDbInfo As String
Dim Source_Dir
Dim NI_FTP_Dir
Dim Tradanet_Dir
Dim RASCAL_Dir
MyFileObject = CreateObject("Scripting.FileSystemObject")
ScriptTimeout = 9999
'##### DEBUGGING SWITCH #####
DebugFlag =
System.Configuration.ConfigurationSettings.AppSettings("Debug")
Dim strDebug As String
If DebugFlag = True Then strDebug = "Debug_"
'###########################
'################## Change Path HERE ##########################
'#### Path is read from app.config file. ####
Source_Dir =
System.Configuration.ConfigurationSettings.AppSettings(strDebug &
"SourcePath")
'################## Change Path HERE ##########################
MyFolder = MyFileObject.GetFolder(Source_Dir)
Folder = MyFileObject.getfolder(MyFolder)
FileColl = CurrentFolder.Files
Dim dFolder As DirectoryInfo = New DirectoryInfo(Folder.path)
Dim fFileArray() As FileInfo = dFolder.GetFiles
' 'FILEARRAY' NOW HOLDS ALL THE FILES IN THE SELECTED FOLDER
Dim fFile As FileInfo
' LOOP THROUGH ARRAY, LISTING ALL FILES IN LISTVIEW
For Each fFile In fFileArray
'Pass filename, filedate, filelastmodified and filesize to SP
'to check if file has changed since last program execution.
strDbInfo = SimpleStoredProcedurewithArguments(fFile.Name)
Next
'###############################################################################################
End Sub
Public Function SimpleStoredProcedurewithArguments(ByVal Parameter As
String) As String
Try
Dim sStoredProcedure As String
Dim dr As System.Data.SqlClient.SqlDataReader
Dim pr As System.Data.SqlClient.SqlParameter
Dim sResults As String
'****************************************
' SET UP THE DATABASE CONNECTION
'****************************************
BuildConnectionString()
ConnectToDatabase()
'****************************************
' SET UP THE STORED PROCEDURE
'****************************************
sStoredProcedure = "SimpleStoredProcedurewithArguments"
cmd = New System.Data.SqlClient.SqlCommand(sStoredProcedure, cnn)
cmd.CommandType = System.Data.CommandType.StoredProcedure
'****************************************
' SET UP PARAMETER
'****************************************
pr = cmd.Parameters.Add("@LogFileName",
System.Data.SqlDbType.VarChar, 50)
pr.Direction = System.Data.ParameterDirection.Input
pr.Value = Parameter + "%"
'****************************************
' RUN THE STORED PROCEDURE
'****************************************
dr = cmd.ExecuteReader()
'****************************************
' SHOW THE RESULTS
'****************************************
sResults = "LogFileName" + vbTab + "LogFileDate" + vbTab + vbTab
+ "LogLastModified" + vbCrLf + vbCrLf + "LogFileSize"
While dr.Read()
sResults = sResults + dr.Item("LogFileName") + vbTab + vbTab
sResults = sResults + dr.Item("LogFileDate") + vbTab + vbTab
sResults = sResults + dr.Item("LogLastModified") + vbTab +
vbTab
sResults = sResults + dr.Item("LogFileSize") + vbTab
End While
dr.Close()
Return sResults
Catch GetError As System.Exception
End Try
End Function
Public Function SimpleStoredProcedureMultipleResults() As String
Try
Dim sStoredProcedure As String
Dim dr As System.Data.SqlClient.SqlDataReader
Dim sResults As String
Dim bNextResult As Boolean
Dim iFields As Integer
Dim iFieldAt As Integer
'****************************************
' SET UP THE DATABASE CONNECTION
'****************************************
BuildConnectionString()
ConnectToDatabase()
'****************************************
' SET UP THE STORED PROCEDURE
'****************************************
sStoredProcedure = "SimpleStoredProcedureMultipleResults"
cmd = New System.Data.SqlClient.SqlCommand(sStoredProcedure, cnn)
cmd.CommandType = System.Data.CommandType.StoredProcedure
'****************************************
' RUN THE STORED PROCEDURE
'****************************************
dr = cmd.ExecuteReader()
'****************************************
' SHOW THE RESULTS
'****************************************
sResults = ""
bNextResult = True
'****************************************
' LOOP THROUGH EACH RESULT
'****************************************
Do Until Not bNextResult
' HOW MANY FIELD/COLUMNS DO WE HAVE
iFields = dr.FieldCount() - 1
While dr.Read()
' LOOP THROUGH EACH FIELD/COLUMN
For iFieldAt = 0 To iFields
sResults = sResults + CStr(dr.Item(iFieldAt)) + vbTab
Next
' LINE BREAK FOR THE ROW
sResults = sResults + vbCrLf
End While
sResults = sResults + vbCrLf + vbCrLf
bNextResult = dr.NextResult
Loop
Return sResults
dr.Close()
Catch GetError As System.Exception
End Try
End Function
Public Sub BuildConnectionString()
'*************************************************
' BUILD THE CONNECTION STRING
'*************************************************
sConnectionString = "SERVER=" + "(local)" + ";"
sConnectionString = sConnectionString + "User ID=" + "newsco" + ";"
sConnectionString = sConnectionString + "Password=" + "nes0lt12" + ";"
sConnectionString = sConnectionString + "Initial Catalog=" +
"EDIExchange"
End Sub
Public Sub ConnectToDatabase()
'*************************************************
' CONNECT TO THE DATABASE
'*************************************************
cnn = New System.Data.SqlClient.SqlConnection(sConnectionString)
cnn.Open()
End Sub
End Class
I writing a project with just one module in it (the reason for this is to
debug code before it becomes a service) and am getting an error which I do
not understand:
No accessible 'Main' method with an appropriate signature was found in
'FTP_Log_Watcher'.
I have set the properties of FTP_Log_Watcher to Startup with 'Sub Main'.
I used to use VB6 about 3-4 years ago, but only as an amatuer. I have only
been using Visual Basic for 2 months - please go easy if it is obvious to you.
Below is the module:
Imports System.IO
Imports System.Data
Public Class EDI_Watcher
Dim gSQLCommandBuilder As System.Data.SqlClient.SqlCommandBuilder
Dim gDataAdapter As System.Data.SqlClient.SqlDataAdapter
Dim gCurrentExample As Integer
Private sDatabase As String
Private sServer As String
Private sUserID As String
Private sPassword As String
Private sConnectionString As String
Private cnn As System.Data.SqlClient.SqlConnection
Private cmd As System.Data.SqlClient.SqlCommand
Public WriteOnly Property Database()
Set(ByVal Value)
sDatabase = Value
End Set
End Property
Public WriteOnly Property Server()
Set(ByVal Value)
sServer = Value
End Set
End Property
Public WriteOnly Property UserID()
Set(ByVal Value)
sUserID = Value
End Set
End Property
Public WriteOnly Property Password()
Set(ByVal Value)
sPassword = Value
End Set
End Property
Public Sub Main(ByVal args() As String)
Call Watcher()
End Sub
Public Sub Watcher()
Const ForReading = 1, ForWriting = 2
Dim MyFileObject
Dim ScriptTimeout
Dim DebugFlag As Boolean
Dim MyFolder
Dim SubFolder
Dim Folder
Dim Date_Comps
Dim Log_Dir
Dim CurrentFolder
Dim FileColl
Dim objFile
Dim strDbInfo As String
Dim Source_Dir
Dim NI_FTP_Dir
Dim Tradanet_Dir
Dim RASCAL_Dir
MyFileObject = CreateObject("Scripting.FileSystemObject")
ScriptTimeout = 9999
'##### DEBUGGING SWITCH #####
DebugFlag =
System.Configuration.ConfigurationSettings.AppSettings("Debug")
Dim strDebug As String
If DebugFlag = True Then strDebug = "Debug_"
'###########################
'################## Change Path HERE ##########################
'#### Path is read from app.config file. ####
Source_Dir =
System.Configuration.ConfigurationSettings.AppSettings(strDebug &
"SourcePath")
'################## Change Path HERE ##########################
MyFolder = MyFileObject.GetFolder(Source_Dir)
Folder = MyFileObject.getfolder(MyFolder)
FileColl = CurrentFolder.Files
Dim dFolder As DirectoryInfo = New DirectoryInfo(Folder.path)
Dim fFileArray() As FileInfo = dFolder.GetFiles
' 'FILEARRAY' NOW HOLDS ALL THE FILES IN THE SELECTED FOLDER
Dim fFile As FileInfo
' LOOP THROUGH ARRAY, LISTING ALL FILES IN LISTVIEW
For Each fFile In fFileArray
'Pass filename, filedate, filelastmodified and filesize to SP
'to check if file has changed since last program execution.
strDbInfo = SimpleStoredProcedurewithArguments(fFile.Name)
Next
'###############################################################################################
End Sub
Public Function SimpleStoredProcedurewithArguments(ByVal Parameter As
String) As String
Try
Dim sStoredProcedure As String
Dim dr As System.Data.SqlClient.SqlDataReader
Dim pr As System.Data.SqlClient.SqlParameter
Dim sResults As String
'****************************************
' SET UP THE DATABASE CONNECTION
'****************************************
BuildConnectionString()
ConnectToDatabase()
'****************************************
' SET UP THE STORED PROCEDURE
'****************************************
sStoredProcedure = "SimpleStoredProcedurewithArguments"
cmd = New System.Data.SqlClient.SqlCommand(sStoredProcedure, cnn)
cmd.CommandType = System.Data.CommandType.StoredProcedure
'****************************************
' SET UP PARAMETER
'****************************************
pr = cmd.Parameters.Add("@LogFileName",
System.Data.SqlDbType.VarChar, 50)
pr.Direction = System.Data.ParameterDirection.Input
pr.Value = Parameter + "%"
'****************************************
' RUN THE STORED PROCEDURE
'****************************************
dr = cmd.ExecuteReader()
'****************************************
' SHOW THE RESULTS
'****************************************
sResults = "LogFileName" + vbTab + "LogFileDate" + vbTab + vbTab
+ "LogLastModified" + vbCrLf + vbCrLf + "LogFileSize"
While dr.Read()
sResults = sResults + dr.Item("LogFileName") + vbTab + vbTab
sResults = sResults + dr.Item("LogFileDate") + vbTab + vbTab
sResults = sResults + dr.Item("LogLastModified") + vbTab +
vbTab
sResults = sResults + dr.Item("LogFileSize") + vbTab
End While
dr.Close()
Return sResults
Catch GetError As System.Exception
End Try
End Function
Public Function SimpleStoredProcedureMultipleResults() As String
Try
Dim sStoredProcedure As String
Dim dr As System.Data.SqlClient.SqlDataReader
Dim sResults As String
Dim bNextResult As Boolean
Dim iFields As Integer
Dim iFieldAt As Integer
'****************************************
' SET UP THE DATABASE CONNECTION
'****************************************
BuildConnectionString()
ConnectToDatabase()
'****************************************
' SET UP THE STORED PROCEDURE
'****************************************
sStoredProcedure = "SimpleStoredProcedureMultipleResults"
cmd = New System.Data.SqlClient.SqlCommand(sStoredProcedure, cnn)
cmd.CommandType = System.Data.CommandType.StoredProcedure
'****************************************
' RUN THE STORED PROCEDURE
'****************************************
dr = cmd.ExecuteReader()
'****************************************
' SHOW THE RESULTS
'****************************************
sResults = ""
bNextResult = True
'****************************************
' LOOP THROUGH EACH RESULT
'****************************************
Do Until Not bNextResult
' HOW MANY FIELD/COLUMNS DO WE HAVE
iFields = dr.FieldCount() - 1
While dr.Read()
' LOOP THROUGH EACH FIELD/COLUMN
For iFieldAt = 0 To iFields
sResults = sResults + CStr(dr.Item(iFieldAt)) + vbTab
Next
' LINE BREAK FOR THE ROW
sResults = sResults + vbCrLf
End While
sResults = sResults + vbCrLf + vbCrLf
bNextResult = dr.NextResult
Loop
Return sResults
dr.Close()
Catch GetError As System.Exception
End Try
End Function
Public Sub BuildConnectionString()
'*************************************************
' BUILD THE CONNECTION STRING
'*************************************************
sConnectionString = "SERVER=" + "(local)" + ";"
sConnectionString = sConnectionString + "User ID=" + "newsco" + ";"
sConnectionString = sConnectionString + "Password=" + "nes0lt12" + ";"
sConnectionString = sConnectionString + "Initial Catalog=" +
"EDIExchange"
End Sub
Public Sub ConnectToDatabase()
'*************************************************
' CONNECT TO THE DATABASE
'*************************************************
cnn = New System.Data.SqlClient.SqlConnection(sConnectionString)
cnn.Open()
End Sub
End Class