E
ECathell
In Theory is this the correct use of a singleton object? I only want them to be able to run this process once(of course by closeing and restarting the application stops that functionality).
Is this setup properly?
Public Class OracleSnapshot
Private Shared m_instance As OracleSnapshot
Private Sub New()
Try
Dim t As System.Threading.Thread
t = New Threading.Thread(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Environment.NewLine)
m.Append(ex.ToString)
MessageBox.Show(m.ToString, "Error Creating Snapshot")
End Try
End Sub
Public Shared Function Activate() As OracleSnapshot
If m_instance Is Nothing Then
m_instance = New OracleSnapshot
End If
Return m_instance
End Function
Private Shared Sub runSnapshot()
Dim config As New Configuration.AppSettingsReader
Dim sqlDatabase, sqlServer As String
sqlDatabase = config.GetValue("databasename", GetType(String))
sqlServer = config.GetValue("servername", GetType(String))
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim mycon As New EricDLL.DatabaseConnection(sqlServer, sqlDatabase)
Try
con.ConnectionString = mycon.ConnectionString
With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SendBeginingInventoryToOracle"
.CommandTimeout = 60
End With
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()
End Try
End Sub
End Class
Is this setup properly?
Public Class OracleSnapshot
Private Shared m_instance As OracleSnapshot
Private Sub New()
Try
Dim t As System.Threading.Thread
t = New Threading.Thread(AddressOf runSnapshot)
Catch ex As Exception
Dim m As New StringBuilder
m.Append("Error Running OracleSnapshot. Processed Failed")
m.Append(Environment.NewLine)
m.Append(ex.ToString)
MessageBox.Show(m.ToString, "Error Creating Snapshot")
End Try
End Sub
Public Shared Function Activate() As OracleSnapshot
If m_instance Is Nothing Then
m_instance = New OracleSnapshot
End If
Return m_instance
End Function
Private Shared Sub runSnapshot()
Dim config As New Configuration.AppSettingsReader
Dim sqlDatabase, sqlServer As String
sqlDatabase = config.GetValue("databasename", GetType(String))
sqlServer = config.GetValue("servername", GetType(String))
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim mycon As New EricDLL.DatabaseConnection(sqlServer, sqlDatabase)
Try
con.ConnectionString = mycon.ConnectionString
With cmd
.Connection = con
.CommandType = CommandType.StoredProcedure
.CommandText = "SendBeginingInventoryToOracle"
.CommandTimeout = 60
End With
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
con.Close()
con.Dispose()
cmd.Dispose()
End Try
End Sub
End Class