Beispiel #1
0
 /// <summary>
 /// Executes the TSQL query provided.
 /// </summary>
 /// <param name="query">The TSQL query text to execute.</param>
 /// <param name="connectionString">The connection string of the database to execute the script against.</param>
 /// <param name="log">The event log to log execptions to. May be null for no logging.</param>
 /// <returns>A list of rows of data returned from the query.</returns>
 override public List <SqlRow> ExecuteQuery(String query, String connectionString, EventLog.EventLog log)
 {
     // Check that the query and connection string are supplied.
     if (!string.IsNullOrWhiteSpace(query) && !string.IsNullOrWhiteSpace(connectionString))
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             Server server = new Server(new ServerConnection(connection));
             try
             {
                 // Execute the query.
                 List <SqlRow> results = new List <SqlRow>();
                 using (SqlDataReader reader = server.ConnectionContext.ExecuteReader(query))
                 {
                     while (reader.Read())
                     {
                         // Add each row's data to the results list.
                         SqlRow row = new SqlRow();
                         for (int i = 0; i < reader.FieldCount; i++)
                         {
                             row.Add(i, reader.GetName(i), reader.GetValue(i));
                         }
                         results.Add(row);
                     }
                 }
                 return(results);
             }
             catch (ExecutionFailureException e)
             {
                 // A non-SQL statement was included in the script.
                 LogException(e, log);
                 return(new List <SqlRow>());
             }
         }
     }
     else
     {
         // The script file was not read.
         return(new List <SqlRow>());
     }
 }
Beispiel #2
0
 /// <summary>
 /// Executes the TSQL query provided.
 /// </summary>
 /// <param name="query">The TSQL query text to execute.</param>
 /// <param name="connectionString">The connection string of the database to execute the script against.</param>
 /// <param name="log">The event log to log execptions to. May be null for no logging.</param>
 /// <returns>A list of rows of data returned from the query.</returns>
 public override List<SqlRow> ExecuteQuery(String query, String connectionString, EventLog.EventLog log)
 {
     // Check that the query and connection string are supplied.
     if (!string.IsNullOrWhiteSpace(query) && !string.IsNullOrWhiteSpace(connectionString))
     {
         using (SqlConnection connection = new SqlConnection(connectionString))
         {
             Server server = new Server(new ServerConnection(connection));
             try
             {
                 // Execute the query.
                 List<SqlRow> results = new List<SqlRow>();
                 using (SqlDataReader reader = server.ConnectionContext.ExecuteReader(query))
                 {
                     while (reader.Read())
                     {
                         // Add each row's data to the results list.
                         SqlRow row = new SqlRow();
                         for (int i = 0; i < reader.FieldCount; i++)
                         {
                             row.Add(i, reader.GetName(i), reader.GetValue(i));
                         }
                         results.Add(row);
                     }
                 }
                 return results;
             }
             catch (ExecutionFailureException e)
             {
                 // A non-SQL statement was included in the script.
                 LogException(e, log);
                 return new List<SqlRow>();
             }
         }
     }
     else
     {
         // The script file was not read.
         return new List<SqlRow>();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Executes the PL/SQL query provided.
        /// </summary>
        /// <param name="query">The PL/SQL query text to execute.</param>
        /// <param name="connectionString">The connection string of the database to execute the script against.</param>
        /// <param name="log">The event log to log execptions to. May be null for no logging.</param>
        /// <param name="exception">Outputs an exception if there was one during the processing of the query. Null otherwise.</param>
        /// <returns>A list of rows of data returned from the query.</returns>
        public List <SqlRow> ExecuteQuery(String query, String connectionString, EventLog.EventLog log, out Exception exception)
        {
            // Check that the query and connection string are supplied.
            if (!string.IsNullOrWhiteSpace(query) && !string.IsNullOrWhiteSpace(connectionString))
            {
                // Get the connection to the database.
                using (OracleConnection connection = new OracleConnection(connectionString))
                {
                    try
                    {
                        // Open the connection to the server.
                        connection.Open();

                        // Create a command that contains the text of the script.
                        using (OracleCommand queryCommand = new OracleCommand())
                        {
                            queryCommand.Connection  = connection;
                            queryCommand.CommandText = query;
                            queryCommand.CommandType = CommandType.Text;

                            // Execute the query.
                            List <SqlRow> results = new List <SqlRow>();
                            using (OracleDataReader reader = queryCommand.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    // Add each row's data to the results list.
                                    while (reader.Read())
                                    {
                                        SqlRow row = new SqlRow();
                                        for (int columnNum = 0; columnNum < reader.FieldCount; columnNum++)
                                        {
                                            row.Add(columnNum, reader.GetName(columnNum), reader.GetValue(columnNum));
                                        }
                                        results.Add(row);
                                    }
                                }
                            }
                            exception = null;
                            return(results);
                        }
                    }
                    catch (OracleException e)
                    {
                        // There was an error executing the script.
                        LogException(e, log);
                        exception = e;
                        return(new List <SqlRow>());
                    }
                    catch (Exception e)
                    {
                        // There was an error executing the script.
                        LogException(e, log);
                        exception = e;
                        return(new List <SqlRow>());
                    }
                }
            }
            else
            {
                // The script file was not read.
                exception = null;
                return(new List <SqlRow>());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Executes the PL/SQL query provided.
        /// </summary>
        /// <param name="query">The PL/SQL query text to execute.</param>
        /// <param name="connectionString">The connection string of the database to execute the script against.</param>
        /// <param name="log">The event log to log execptions to. May be null for no logging.</param>
        /// <param name="exception">Outputs an exception if there was one during the processing of the query. Null otherwise.</param>
        /// <returns>A list of rows of data returned from the query.</returns>
        public List<SqlRow> ExecuteQuery(String query, String connectionString, EventLog.EventLog log, out Exception exception)
        {
            // Check that the query and connection string are supplied.
            if (!string.IsNullOrWhiteSpace(query) && !string.IsNullOrWhiteSpace(connectionString))
            {
                // Get the connection to the database.
                using (OracleConnection connection = new OracleConnection(connectionString))
                {
                    try
                    {
                        // Open the connection to the server.
                        connection.Open();

                        // Create a command that contains the text of the script.
                        using (OracleCommand queryCommand = new OracleCommand())
                        {
                            queryCommand.Connection = connection;
                            queryCommand.CommandText = query;
                            queryCommand.CommandType = CommandType.Text;

                            // Execute the query.
                            List<SqlRow> results = new List<SqlRow>();
                            using (OracleDataReader reader = queryCommand.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    // Add each row's data to the results list.
                                    while (reader.Read())
                                    {
                                        SqlRow row = new SqlRow();
                                        for (int columnNum = 0; columnNum < reader.FieldCount; columnNum++)
                                        {
                                            row.Add(columnNum, reader.GetName(columnNum), reader.GetValue(columnNum));
                                        }
                                        results.Add(row);
                                    }
                                }
                            }
                            exception = null;
                            return results;
                        }
                    }
                    catch (OracleException e)
                    {
                        // There was an error executing the script.
                        LogException(e, log);
                        exception = e;
                        return new List<SqlRow>();
                    }
                    catch (Exception e)
                    {
                        // There was an error executing the script.
                        LogException(e, log);
                        exception = e;
                        return new List<SqlRow>();
                    }
                }
            }
            else
            {
                // The script file was not read.
                exception = null;
                return new List<SqlRow>();
            }
        }