Skip to main content

Class DatabaseUtil

Namespace: Workspace.XBR.Xperiflow.Utilities.Database

Assembly: Xperiflow.dll

Declaration
public static class DatabaseUtil

Methods

GetDatabaseConnection(SessionInfo, string)

Retrieves a database connection info based on a connection key.

Declaration
public static DbConnInfo GetDatabaseConnection(SessionInfo si, string connectionKey)
Returns

OneStream.Shared.Database.DbConnInfo

A DbConnInfo object containing the connection information for the specified connection key.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to retrieve.

CreateDbConnInfo(SessionInfo, string)

Creates a database connection info based on a connection key.

Declaration
public static DbConnInfo CreateDbConnInfo(SessionInfo si, string connectionKey)
Returns

OneStream.Shared.Database.DbConnInfo

A DbConnInfo object containing the connection information for the specified connection key.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to retrieve.

GetAppDatabaseConnectionString(SessionInfo)

Gets the database server connection for the current application.

Declaration
public static string GetAppDatabaseConnectionString(SessionInfo si)
Returns

System.String

Parameters
TypeName
OneStream.Shared.Common.SessionInfosi

GetFrameworkDatabaseConnectionString(SessionInfo)

Get the database server connection for the framework.

Declaration
public static string GetFrameworkDatabaseConnectionString(SessionInfo si)
Returns

System.String

Parameters
TypeName
OneStream.Shared.Common.SessionInfosi
Exceptions

OneStream.Shared.Common.XFException

GetConnectionString(SessionInfo, string)

Retrieves a list of available database connection options.

Declaration
public static string GetConnectionString(SessionInfo si, string connectionKey)
Returns

System.String

Parameters
TypeName
OneStream.Shared.Common.SessionInfosi
System.StringconnectionKey

GetConnectionStringOptions(SessionInfo, bool)

Retrieves a list of available database connection options.

Declaration
public static DataTable GetConnectionStringOptions(SessionInfo si, bool externalOnly = false)
Returns

System.Data.DataTable

A DataTable containing the names of the available database connections as the "Value1" and "Value2" columns.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.BooleanexternalOnlyIf true, only external database connections will be included in the list.

MapDatabaseServerConnectionToDatabaseServerMetadata(SessionInfo, DatabaseServerConnection)

Declaration
public static DatabaseServerMetadata MapDatabaseServerConnectionToDatabaseServerMetadata(SessionInfo si, DatabaseServerConnection databaseServerConnection)
Returns

Workspace.XBR.Xperiflow.Utilities.Database.DatabaseServerMetadata

Parameters
TypeName
OneStream.Shared.Common.SessionInfosi
OneStream.Shared.Wcf.DatabaseServerConnectiondatabaseServerConnection

DeleteDatabaseTable(SessionInfo, string, string)

Executes a SQL statement using a specified database connection key to delete a database table if the table exists.

Declaration
public static void DeleteDatabaseTable(SessionInfo si, string connectionKey, string tableName)
Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to use for the operation.
System.StringtableNameThe name of the database table to be deleted.

GetDatabaseTableNames(SessionInfo, string, bool, bool)

Retrieves the list of database tables that exist within a given database.

Declaration
public static DataTable GetDatabaseTableNames(SessionInfo si, string connectionKey, bool includeTableSchema = true, bool orderTable = true)
Returns

System.Data.DataTable

A DataTable with one column "Table".

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to use for the operation.
System.BooleanincludeTableSchemaWhether or not to include "dbo." as the prefix to the table.
System.BooleanorderTableWhether or not to order the table desc.

GetDatabaseTableNameExists(SessionInfo, string, string)

Gets whether or not a database table exists in the database for given database connection.

Declaration
public static bool GetDatabaseTableNameExists(SessionInfo si, string connectionKey, string tableName)
Returns

System.Boolean

A boolean value: True if the database table exists and False if it does not.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to use for the operation.
System.StringtableNameThe name of the database table.

GetDatabaseTableColumnDistinct(SessionInfo, string, string, string)

Retrieves the distinct values found with a column name in a database table.

Declaration
public static DataTable GetDatabaseTableColumnDistinct(SessionInfo si, string connectionKey, string tableName, string columnName)
Returns

System.Data.DataTable

A DataTable containing all the values from the column in the specified database table.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to use for the operation.
System.StringtableNameThe name of the database table.
System.StringcolumnNameThe name of the column of interest in the databse table.

GetDatabaseTableSchema(SessionInfo, string, string)

Retrieves the Database Table Schema for the given table.

Declaration
public static DataTable GetDatabaseTableSchema(SessionInfo si, string connectionKey, string tableName)
Returns

System.Data.DataTable

A DataTable with the given database table's schema.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionKeyThe key of the database connection to use for the operation.
System.StringtableNameThe name of the database table.

GetDatabaseTableColumnSchema(SessionInfo, string, string)

Retrieves the column schema of a database table as a DataColumnCollection, providing detailed information about each column's data type and properties.

Declaration
public static DataColumnCollection GetDatabaseTableColumnSchema(SessionInfo si, string connectionKey, string tableName)
Remarks

This method retrieves the column schema by executing a "SELECT TOP(1) * FROM [tableName]" query and extracting the column information from the resulting DataTable structure. This approach provides the most accurate representation of the table's column schema as it would appear when data is retrieved.

Performance Note:

Only one row is retrieved to minimize data transfer while still obtaining complete schema information. This is much more efficient than retrieving all data when only schema information is needed.

Returns

System.Data.DataColumnCollection

A System.Data.DataColumnCollection containing the schema information for all columns in the specified table. Each System.Data.DataColumn includes column name, data type, constraints, and other metadata.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session
System.StringconnectionKeyThe key of the database connection to use for the operation
System.StringtableNameThe name of the database table
Exceptions

OneStream.Shared.Common.XFException Thrown when database connection fails or table does not exist System.NullReferenceException Thrown when the SQL query returns a null reference

ExtractDatabaseTable(SessionInfo, string, string, int)

Extracts data from a database table into a DataTable, with optional row limiting for memory management.

Declaration
public static DataTable ExtractDatabaseTable(SessionInfo si, string connectionKey, string tableName, int records = -1)
Remarks

This method performs a direct extraction of database table data into memory using a DataTable structure. It uses SQL Server's nolock hint to avoid blocking other database operations, which is suitable for read-only data extraction scenarios.

Memory Considerations:

When extracting large tables, be aware of memory usage. Use the records parameter to limit the result set size for large tables. For extremely large datasets, consider using batch processing approaches instead.

Performance Notes:

  • Uses WITH (NOLOCK) hint to avoid blocking other database operations

  • TOP clause is used when record limiting is specified

  • Consider indexing on frequently queried columns for better performance

Returns

System.Data.DataTable

A System.Data.DataTable containing the data from the specified table. The DataTable will contain up to the specified number of records, or all records if no limit is specified.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe OneStream Session Info object for the current session
System.StringconnectionKeyThe database connection key identifying which database to query
System.StringtableNameThe name of the table to retrieve data from
System.Int32recordsThe number of top records to return. If -1 (default), all records will be returned.
Use positive integers to limit the result set for memory management.
Exceptions

OneStream.Shared.Common.XFException Thrown when database connection fails or table does not exist System.OutOfMemoryException Thrown when the table is too large to fit in memory

PersistDatabaseTable(SessionInfo, string, DataTable, BlendTableLoadTypes, BlendTableIndexTypes)

Persists a .NET DataTable as a database table within the database specified by the connection key, with configurable load behavior and indexing options.

Declaration
public static void PersistDatabaseTable(SessionInfo si, string connectionKey, DataTable dt, BlendTableLoadTypes loadType, BlendTableIndexTypes indexType)
Remarks

This method provides a high-level interface for persisting in-memory DataTable objects as database tables. It internally handles the creation of the database table schema based on the DataTable column definitions and then bulk-inserts the data.

Table Creation Process:

  1. Validates that the DataTable has a TableName property set

  2. Creates the database table schema using Workspace.XBR.Xperiflow.Utilities.Database.DatabaseUtil.CreateDatabaseTable(OneStream.Shared.Common.SessionInfo%2cSystem.Data.DataTable%2cSystem.String%2cOneStream.Shared.Common.BlendTableLoadTypes%2cOneStream.Shared.Common.BlendTableIndexTypes)

  3. Bulk-inserts the data using OneStream.Stage.Engine.BiBlendTableHelper.PersistBlendTable(OneStream.Shared.Common.SessionInfo%2cSystem.Data.DataTable%2cSystem.String)

Performance Considerations:

  • Use appropriate indexing for frequently queried columns

  • Consider load type impact: Replace operations are slower for large tables

  • Append operations are fastest for adding new data

  • Batch large datasets for optimal performance

Data Type Mapping:

The method automatically maps .NET DataTable column types to appropriate SQL Server data types. String columns use NVARCHAR with appropriate sizing based on content analysis.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session
System.StringconnectionKeyThe key of the database connection to use for the operation
System.Data.DataTabledtThe DataTable to persist as a database table. The System.Data.DataTable.TableName property
must be set to specify the target database table name.
OneStream.Shared.Common.BlendTableLoadTypesloadTypeThe type of operation to perform when persisting the data:
_ Create: Creates a new table (fails if table already exists)
_ Replace: Drops and recreates the table with new data
* Append: Adds data to existing table (creates if doesn't exist)
OneStream.Shared.Common.BlendTableIndexTypesindexTypeThe type of database indexing to apply to the persisted table for performance optimization.
Choose based on expected query patterns and table size.
Exceptions

System.ArgumentException Thrown when the DataTable doesn't have a TableName property set OneStream.Shared.Common.XFException Thrown when database operations fail, including connection issues, permission problems, or schema conflicts

GetDatabaseTableDistinctColumnValues(SessionInfo, string, string, List<string>, bool)

Retrieves the distinct values of specified columns from a database table. This method executes a SQL query that selects distinct combinations of values from the given columns, providing a de-duplicated dataset based on the selected columns.

Declaration
public static DataTable GetDatabaseTableDistinctColumnValues(SessionInfo si, string connectionKey, string tableName, List<string> columnNames, bool useCommandTimeoutLarge = false)
Remarks

This method is designed to efficiently retrieve distinct values from large tables. It can be useful in scenarios where you need to group or filter data based on certain columns or create batch processing logic.

Returns

System.Data.DataTable

A System.Data.DataTable containing the distinct values for the specified columns in the table. Each row in the returned System.Data.DataTable represents a unique combination of values across the specified columns.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session information used for database connections and user context.
System.StringconnectionKeyThe key representing the database connection string, identifying which database to query.
System.StringtableNameThe name of the table from which to retrieve distinct column values.
System.Collections.Generic.List<System.String>columnNamesA list of column names for which distinct values should be retrieved. These columns must exist in the table.
System.BooleanuseCommandTimeoutLargeOptional. If true, uses a larger command timeout for the query execution.
Defaults to false, meaning the query uses the standard timeout value.
Exceptions

System.ArgumentException Thrown if the table name or the column names are invalid, or if any of the specified columns do not exist in the table. OneStream.Shared.Common.XFException A wrapped exception thrown if an error occurs during the execution of the SQL query. This includes any underlying database connectivity issues, SQL syntax errors, or command execution timeouts. The original exception is logged for debugging.

GetTableBatchByDistinctGroups(SessionInfo, string, string, List<string>, int, bool)

Retrieves batches of rows from a database table based on distinct groupings of specified columns. The table is queried in chunks to efficiently handle large datasets without loading the entire table into memory.

Declaration
public static IEnumerable<DataTable> GetTableBatchByDistinctGroups(SessionInfo si, string connectionKey, string tableName, List<string> intersectionColumns, int batchSize = 100, bool useCommandTimeoutLarge = false)
Remarks

This method is useful when working with large tables where it's important to process data in smaller, more manageable batches. It retrieves distinct values for the specified intersection columns and then selects rows that match each unique combination of values. The method will yield batches of System.Data.DataTable objects, each containing the selected rows for a set of distinct groupings.

Returns

System.Collections.Generic.IEnumerable<System.Data.DataTable>

An enumerable sequence of System.Data.DataTable objects, where each System.Data.DataTable contains a batch of rows matching the specified distinct groupings of the intersection columns.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session information used for database connections and user context.
System.StringconnectionKeyThe key representing the database connection string.
System.StringtableNameThe name of the table to query.
System.Collections.Generic.List<System.String>intersectionColumnsA list of column names used to define unique groupings of data.
System.Int32batchSizeThe number of distinct groups to process in each batch. Default is 100. Note that this does not mean 100 rows, this means 100 distinct combinations of the intersectionColumns.
System.BooleanuseCommandTimeoutLargeIf set to true, uses a larger command timeout when executing queries. Default is false.
Exceptions

System.ArgumentException Thrown if the table does not exist, the intersection columns are invalid or empty, or if a specified column does not exist in the table.

SelectFromTableWithRowLimit(SessionInfo, string, string, int)

Retrieves the top rowLimit rows from a database table.

Declaration
public static DataTable SelectFromTableWithRowLimit(SessionInfo si, string connectionKey, string tableName, int rowLimit)
Returns

System.Data.DataTable

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session information used for database connections and user context.
System.StringconnectionKeyThe key representing the database connection string.
System.StringtableNameThe name of the table to query.
System.Int32rowLimitThe maximum number of rows to retrieve from the table.

InsertTopClause(string, int)

Modifes a SQL query to include a TOP clause to limit the number of rows returned.

Declaration
public static string InsertTopClause(string sql, int top)
Returns

System.String

Parameters
TypeNameDescription
System.StringsqlThe SQL query to modify.
System.Int32topThe number of rows to limit the query to.

SelectFromTableWithDataLimit(SessionInfo, string, string, long)

Selects data from a database table with a byte limit on the data returned.

Declaration
public static DatabaseUtil.SelectFromTableWithDataLimitResponse SelectFromTableWithDataLimit(SessionInfo si, string connectionString, string query, long byteLimit)
Returns

Workspace.XBR.Xperiflow.Utilities.Database.DatabaseUtil.SelectFromTableWithDataLimitResponse

A SelectFromTableWithDataLimitResponse containing the DataTable and information about the query.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session info object for the current session.
System.StringconnectionStringThe connection string to the database.
System.StringqueryThe SQL query to execute. Should be a SELECT statement.
System.Int64byteLimitThe maximum number of bytes to return in the data.

CreateDatabaseTable(SessionInfo, DataTable, string, BlendTableLoadTypes, BlendTableIndexTypes)

Creates a Database table based on the DataTable structure and schema. No data is inserted.

Declaration
public static void CreateDatabaseTable(SessionInfo si, DataTable dt, string dbLocationOrExternalConName, BlendTableLoadTypes loadType, BlendTableIndexTypes indexType)
Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe OneStream SessionInfo object
System.Data.DataTabledtThe DataTable object that contains the schema of the table to be created
System.StringdbLocationOrExternalConNameThe database location or external connection name where the table will be created.
OneStream.Shared.Common.BlendTableLoadTypesloadTypeThe type of table creation to be performed. Options include Append, AppendDropRecreateIndexes, or DropAndRecreate.
OneStream.Shared.Common.BlendTableIndexTypesindexTypeThe type of index to be created. Options include NoIndexes, MirrorDataTableIndexes or ClusteredColStore.

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?