private static bool PerformMySqlConnectionStringValidation(string connectionString) { string trimedConnectionString = connectionString.Replace(" ", string.Empty); if (!trimedConnectionString.Contains("AllowUserVariables=True")) { ConnectionVariableNotEnabledException cvnee = new ConnectionVariableNotEnabledException("AllowUserVariables=True"); Logger.Error(cvnee); throw cvnee; } if (!trimedConnectionString.Contains("CheckParameters=False")) { ConnectionVariableNotEnabledException cvnee = new ConnectionVariableNotEnabledException("CheckParameters=False"); Logger.Error(cvnee); throw cvnee; } return(true); }
internal object ExecuteScalar(string transaction, string connectionToUse, bool returnDataTable) { if (string.IsNullOrWhiteSpace(transaction)) { return(null); } try { Logger.Info(string.Format("Starting execution for transaction using connection {0}", connectionToUse)); using (DbConnection connection = _connectionType == ConnectionTypes.MySQL ? (DbConnection)Connection.OpenMySqlConnection(connectionToUse) : (DbConnection)Connection.OpenMsSqlConnection(connectionToUse)) { if (connection.State != ConnectionState.Open) { throw new BadConnectionStateException(); } _command = connection.CreateCommand(); _command.CommandType = CommandType.Text; if (returnDataTable) { _command.CommandText = transaction; System.Data.DataTable dataTable = new System.Data.DataTable(); dataTable.Load(_command.ExecuteReader()); Logger.Info(string.Format("Execution for transaction using connection {0} has finished successfully.", connectionToUse)); return(dataTable); } else { object scalar = null; string[] queries = transaction.Split(new string[] { "|;|" }, StringSplitOptions.None); for (int i = 0; i < queries.Length; i++) { _command.CommandText = queries[i]; scalar = _command.ExecuteScalar(); } Logger.Info(string.Format("Execution for transaction using connection {0} has finished successfully.", connectionToUse)); return(scalar); } } } catch (DbException dbException) { if (dbException.InnerException != null) { if (dbException.InnerException.Message.EndsWith("must be defined.")) { ConnectionVariableNotEnabledException cvnee = new ConnectionVariableNotEnabledException("AllowUserVariables=True"); Logger.Error(cvnee); throw cvnee; } } Logger.Error(dbException); throw dbException; } catch (Exception exception) { Logger.Error(exception); throw; } }