Add RegexEditor, Improve Database Add Language
This commit is contained in:
@@ -2,12 +2,17 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class MSSQLServer
|
||||
Inherits BaseClass
|
||||
|
||||
Public DBInitialized As Boolean = False
|
||||
Public CurrentSQLConnectionString As String = ""
|
||||
|
||||
Private _Timeout As Integer
|
||||
Private _Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, ConnectionString As String)
|
||||
Public Sub New(LogConfig As LogConfig, ConnectionString As String, Optional Timeout As Integer = 120)
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Timeout = Timeout
|
||||
|
||||
CurrentSQLConnectionString = ConnectionString
|
||||
|
||||
@@ -19,6 +24,31 @@ Public Class MSSQLServer
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Server As String, Database As String, UserId As String, Password As String, Optional Timeout As Integer = 120)
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Timeout = Timeout
|
||||
|
||||
CurrentSQLConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
|
||||
Try
|
||||
DBInitialized = TestCanConnect()
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Shared Function GetConnectionString(Server As String, Database As String, UserId As String, Password As String) As String
|
||||
Dim oConnectionStringBuilder As New SqlConnectionStringBuilder() With {
|
||||
.DataSource = Server,
|
||||
.InitialCatalog = Database,
|
||||
.UserId = UserId,
|
||||
.Password = Password
|
||||
}
|
||||
|
||||
Return oConnectionStringBuilder.ToString
|
||||
End Function
|
||||
|
||||
Private Function TestCanConnect() As Boolean
|
||||
Try
|
||||
Dim oConnection As New SqlConnection(CurrentSQLConnectionString)
|
||||
@@ -41,14 +71,13 @@ Public Class MSSQLServer
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Returns a datatable for a sql-statement
|
||||
''' </summary>
|
||||
''' <param name="sqlcommand">sqlcommand for datatable (select XYZ from TableORView)</param>
|
||||
''' <param name="Timeout">Optional Timeout</param>
|
||||
''' <param name="SqlCommand">sqlcommand for datatable (select XYZ from TableORView)</param>
|
||||
''' <returns>Returns a datatable</returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function GetDatatable(sqlcommand As String, Optional Timeout As Integer = 120) As DataTable
|
||||
Public Overrides Function GetDatatable(SqlCommand As String) As DataTable
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
@@ -56,8 +85,8 @@ Public Class MSSQLServer
|
||||
|
||||
Using oConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = sqlcommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = _Timeout
|
||||
|
||||
Dim dt As DataTable = New DataTable()
|
||||
Dim oAdapter As SqlDataAdapter = New SqlDataAdapter(oSQLCOmmand)
|
||||
@@ -67,23 +96,23 @@ Public Class MSSQLServer
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Debug("sqlcommand: " & sqlcommand)
|
||||
_Logger.Debug("sqlcommand: " & SqlCommand)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes the passed sql-statement
|
||||
''' </summary>
|
||||
''' <param name="executeStatement">the sql statement</param>
|
||||
''' <param name="Timeout">Optional Timeout</param>
|
||||
''' <returns>Returns true if properly executed, else false</returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function NewExecutenonQuery(executeStatement As String, Optional Timeout As Integer = 120) As Boolean
|
||||
Public Function NewExecutenonQuery(executeStatement As String) As Boolean
|
||||
_Logger.Warn("NewExecutenonQuery is deprecated. Use ExecuteNonQuery instead.")
|
||||
Return ExecuteNonQuery(executeStatement, Timeout)
|
||||
Return ExecuteNonQuery(executeStatement)
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQuery(SQLCommand As String, Optional Timeout As Integer = 120) As Boolean
|
||||
Public Overrides Function ExecuteNonQuery(SQLCommand As String) As Boolean
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
@@ -92,7 +121,7 @@ Public Class MSSQLServer
|
||||
Using oConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SQLCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.CommandTimeout = _Timeout
|
||||
oSQLCOmmand.ExecuteNonQuery()
|
||||
Return True
|
||||
End Using
|
||||
@@ -108,15 +137,13 @@ Public Class MSSQLServer
|
||||
''' Executes the passed sql-statement as Scalar
|
||||
''' </summary>
|
||||
''' <param name="ScalarSQL">the sql statement</param>
|
||||
''' <param name="Timeout">Optional Timeout</param>
|
||||
''' <returns>Returns true if properly executed, else false</returns>
|
||||
''' <remarks></remarks>
|
||||
Public Function NewExecuteScalar(ScalarSQL As String, Optional Timeout As Integer = 120) As Object
|
||||
Public Function NewExecuteScalar(ScalarSQL As String) As Object
|
||||
_Logger.Warn("NewExecuteScalar is deprecated. Use GetScalarValue instead.")
|
||||
Return GetScalarValue(ScalarSQL, Timeout)
|
||||
Return GetScalarValue(ScalarSQL)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(SQLQuery As String, Optional Timeout As Integer = 120) As Object
|
||||
Public Overrides Function GetScalarValue(SQLQuery As String) As Object
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
@@ -125,7 +152,7 @@ Public Class MSSQLServer
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Using oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SQLQuery
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.CommandTimeout = _Timeout
|
||||
Dim oResult As Object = oSQLCOmmand.ExecuteScalar()
|
||||
Return oResult
|
||||
End Using
|
||||
|
||||
Reference in New Issue
Block a user