Skip to main content
Version: 2025

SalSqlSessionHandle

Namespace: PPJ.Runtime.Sql

Assembly: PPJ.Web.50 (5.0.0.0)

Represents a database session shared by statement handles.

public struct SalSqlSessionHandle : ValueType, ISerializable, IXmlSerializable

Copies of this value refer to the same runtime SQL object. Boolean-returning operations can return the value supplied by SQL error handling; unhandled SQL errors are thrown.

Example:

using PPJ.Runtime.Sql;

var handle = SalSqlSessionHandle.Null;
if (handle.Create("your provider connection string"))
{
try
{
var statement = SalSqlHandle.Null;
if (handle.CreateStatement(ref statement))
statement.Disconnect();
}
finally { handle.Free(); }
}

Properties

Instance member Connection

IDbConnection: Gets the underlying ADO.NET database connection.

Instance member Handle

IntPtr: Gets the runtime handle, or Zero when unassigned.

Instance member IsNull

Boolean: Gets whether the underlying handle is zero.

Instance member LastError

SalSqlError: Gets the most recent SQL error, including connection validation errors, or when none is recorded.

Instance member LastErrorCode

SalNumber: Gets the last SQL error number, or zero when no error is recorded.

Instance member LastErrorMessage

SalString: Gets the last SQL error message, or an empty string when no error is recorded.

Instance member LastErrorPosition

SalNumber: Gets the statement position reported by the last SQL error, or zero when no error is recorded.

Instance member Properties

SqlProperties: Gets the database configuration used by the connection.

Instance member Transaction

IDbTransaction: Gets the current transaction associated with the connection.

Methods

Instance member BeginTransaction()

Starts or retrieves the connection transaction when autocommit is disabled.

Returns: IDbTransaction. The transaction, or when autocommit is enabled.

Instance member Commit()

Commits the transaction shared by statements using this database connection.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member Commit(errorHandler)

Commits the transaction shared by statements using this database connection.

ParameterTypeDescription
errorHandlerWhenSqlErrorHandlerThe SQL error handler to use for the duration of this operation.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member Create(connectionString)

Acquires a database session using the current SQL database and credentials and the supplied connection string.

ParameterTypeDescription
connectionStringStringThe provider connection string used to acquire the session.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

The database, user, and password come from Database, User, and Password.

Instance member Create(connectionString, errorHandler)

Acquires a database session using the current SQL database and credentials and the supplied connection string.

ParameterTypeDescription
connectionStringStringThe provider connection string used to acquire the session.
errorHandlerWhenSqlErrorHandlerThe SQL error handler to use for the duration of this operation.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

The database, user, and password come from Database, User, and Password.

Instance member CreateStatement(hSql)

Creates a statement handle associated with this session.

ParameterTypeDescription
hSql by referenceSalSqlHandleReceives the newly created statement handle.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member Free()

Releases this session reference to its database connection.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member Free(errorHandler)

Releases this session reference to its database connection.

ParameterTypeDescription
errorHandlerWhenSqlErrorHandlerThe SQL error handler to use for the duration of this operation.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Static member FromHandle(handle)

Resolves a SQL handle registered with the runtime.

ParameterTypeDescription
handleIntPtrThe registered runtime handle to resolve.

Returns: SalSqlSessionHandle. The wrapper for the registered handle, or a null handle when the value is zero.

Instance member GetErrorInfo(nErrorNumber, sErrorDescription, sSqlState)

Copies the last SQL error and connection state into the supplied variables.

ParameterTypeDescription
nErrorNumber by referenceSalNumberReceives the error number, or zero when no error is recorded.
sErrorDescription by referenceSalStringReceives the error description, or a null SAL string when no error is recorded.
sSqlState by referenceSalStringReceives the connection state name; this is not a provider SQLSTATE code.

Returns: Boolean. if an error is available; otherwise, .

Instance member GetObjectData(info, context)

Serializes the runtime handle.

ParameterTypeDescription
infoSerializationInfoThe serialization record that receives the handle.
contextStreamingContextThe serialization context; this implementation does not use it.

Serialization stores the handle value only; it does not serialize or recreate a database connection.

Instance member GetParameter(parameter, nValue, sValue)

Reads a supported database configuration parameter.

ParameterTypeDescription
parameterInt32The Sys.DBP_* identifier of the setting.
nValue by referenceSalNumberReceives the numeric setting when applicable.
sValue by referenceSalStringReceives the string setting when applicable.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling. Unsupported parameter identifiers return false.

The numeric or string output receives the value appropriate to the selected parameter.

Instance member Rollback()

Rolls back the transaction shared by statements using this database connection.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member Rollback(errorHandler)

Rolls back the transaction shared by statements using this database connection.

ParameterTypeDescription
errorHandlerWhenSqlErrorHandlerThe SQL error handler to use for the duration of this operation.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling.

Instance member SetParameter(parameter, numberValue, stringValue)

Changes a supported database configuration parameter.

ParameterTypeDescription
parameterInt32The Sys.DBP_* identifier of the setting.
numberValueInt32The numeric value, used for numeric and Boolean settings.
stringValueStringThe value for a string setting.

Returns: Boolean. True when the operation succeeds; on a SQL error, the value returned by SQL error handling. Unsupported parameter identifiers return false.

Supported parameters include DBP_BRAND, DBP_VERSION, DBP_LOCKWAITTIMEOUT, DBP_AUTOCOMMIT, and DBP_ISOLEVEL.

Used By

NameDescription
Sal.WindowHandleToNumberReturns a runtime handle identifier as a SAL number.
SalSqlHandle.GetSessionHandleGets the session used to create this statement handle.
SalSqlSessionHandle.FromHandleResolves a SQL handle registered with the runtime.
Sql.CommitSession
Sql.CreateStatement
Sql.RollbackSession
Sql.GetSessionErrorInfo
Sql.SetSessionParameter
Sql.GetSessionParameter