Click or drag to resize

AdoDataConnection Class

Creates a new IDbConnection from any specified or configured ADO.NET data source.
Inheritance Hierarchy
SystemObject
  GSF.DataAdoDataConnection

Namespace: GSF.Data
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public class AdoDataConnection : IDisposable
View Source

The AdoDataConnection type exposes the following members.

Constructors
 NameDescription
Public methodAdoDataConnection(String) Creates and opens a new AdoDataConnection based on connection settings in configuration file.
Public methodAdoDataConnection(String, String) Creates and opens a new AdoDataConnection from specified connectionString and dataProviderString.
Public methodAdoDataConnection(IDbConnection, Type, Boolean) Creates a new AdoDataConnection from specified connection and adapterType.
Public methodAdoDataConnection(String, Type, Type) Creates and opens a new AdoDataConnection from specified connectionString, connectionType, and adapterType.
Top
Properties
 NameDescription
Public propertyAdapterType Gets the type of data adapter for configured ADO.NET data source.
Public propertyConnection Gets an open IDbConnection to configured ADO.NET data source.
Public propertyDatabaseType Gets or sets the type of the database underlying the AdoDataConnection.
Public propertyDefaultIsolationLevel Gets the default IsolationLevel for the connected AdoDataConnection database type.
Public propertyDefaultTimeout Gets or sets default timeout for AdoDataConnection data operations.
Public propertyIsJetEngine Gets a value to indicate whether source database is Microsoft Access.
Public propertyIsMySQL Gets a value to indicate whether source database is MySQL.
Public propertyIsOracle Gets a value to indicate whether source database is Oracle.
Public propertyIsPostgreSQL Gets a value to indicate whether source database is PostgreSQL.
Public propertyIsSqlite Gets a value to indicate whether source database is SQLite.
Public propertyIsSQLServer Gets a value to indicate whether source database is Microsoft SQL Server.
Public propertyUtcNow Gets current UTC date-time in an implementation that is proper for the connected AdoDataConnection database type.
Top
Methods
 NameDescription
Public methodBool Returns proper Boolean implementation for connected AdoDataConnection database type.
Public methodDispose Releases all the resources used by the AdoDataConnection object.
Protected methodDispose(Boolean) Releases the unmanaged resources used by the AdoDataConnection object and optionally releases the managed resources.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodEscapeIdentifier Escapes an identifier, e.g., a table or field name, using the common delimiter for the connected AdoDataConnection database type or the standard ANSI escaping delimiter, i.e., double-quotes, based on the useAnsiQuotes flag.
Public methodExecuteNonQuery(String, Object) Executes the SQL statement using Connection, and returns the number of rows affected.
Public methodExecuteNonQuery(Int32, String, Object) Executes the SQL statement using Connection, and returns the number of rows affected.
Public methodExecuteReader(String, Object) Executes the SQL statement using Connection, and builds a IDataReader.
Public methodExecuteReader(Int32, String, Object) Executes the SQL statement using Connection, and builds a IDataReader.
Public methodExecuteReader(CommandBehavior, Int32, String, Object) Executes the SQL statement using Connection, and builds a IDataReader.
Public methodExecuteScalar(String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set.
Public methodExecuteScalar(Int32, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set.
Public methodExecuteScalar(Type, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type returnType.
Public methodExecuteScalar(Type, Int32, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type returnType.
Public methodExecuteScalar(Type, Object, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type returnType, substituting defaultValue if Value is retrieved.
Public methodExecuteScalar(Type, Object, Int32, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type returnType, substituting defaultValue if Value is retrieved.
Public methodExecuteScalarT(String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type T.
Public methodExecuteScalarT(Int32, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type T.
Public methodExecuteScalarT(T, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type T, substituting defaultValue if Value is retrieved.
Public methodExecuteScalarT(T, Int32, String, Object) Executes the SQL statement using Connection, and returns the value in the first column of the first row in the result set as type T, substituting defaultValue if Value is retrieved.
Public methodExecuteScript(String) Executes the given SQL script using Connection.
Public methodExecuteScript(TextReader) Executes the given SQL script using Connection.
Protected methodFinalize Releases the unmanaged resources before the AdoDataConnection object is reclaimed by GC.
(Overrides ObjectFinalize)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodGuid(Guid) Returns proper Guid implementation for connected AdoDataConnection database type.
Public methodGuid(DataRow, String) Retrieves Guid from a DataRow field based on database type.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodParameterizedQueryString Creates a parameterized query string for the underlying database type based on the given format string and parameter names.
Public methodStatic memberReloadConfigurationSettings Forces a reload of cached configuration connection settings.
Public methodRetrieveData(String, Object) Executes the SQL statement using Connection, and returns the first DataTable of result set, if the result set contains at least one table.
Public methodRetrieveData(Int32, String, Object) Executes the SQL statement using Connection, and returns the first DataTable of result set, if the result set contains at least one table.
Public methodRetrieveDataSet(String, Object) Executes the SQL statement using Connection, and returns the DataSet that may contain multiple tables, depending on the SQL statement.
Public methodRetrieveDataSet(Int32, String, Object) Executes the SQL statement using Connection, and returns the DataSet that may contain multiple tables, depending on the SQL statement.
Public methodRetrieveRow(String, Object) Executes the SQL statement using Connection, and returns the first DataRow in the result set.
Public methodRetrieveRow(Int32, String, Object) Executes the SQL statement using Connection, and returns the first DataRow in the result set.
Public methodStatic memberToDataProviderString Generates a data provider string for the given connection type and adapter type.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodTryRetrieveRow(String, DataRow, Object) Tries to retrieve the first DataRow in the result set of the SQL statement using Connection.
Public methodTryRetrieveRow(Int32, String, DataRow, Object) Tries to retrieve the first DataRow in the result set of the SQL statement using Connection.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Remarks
Example connection and data provider strings:
Database typeExample connection string / data provider string
SQL Server ConnectionString = "Data Source=serverName; Initial Catalog=databaseName; User ID=userName; Password=password"
DataProviderString = "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.SqlClient.SqlConnection; AdapterType=System.Data.SqlClient.SqlDataAdapter"
Oracle ConnectionString = "Data Source=tnsName; User ID=schemaUserName; Password=schemaPassword"
DataProviderString = "AssemblyName={Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342}; ConnectionType=Oracle.DataAccess.Client.OracleConnection; AdapterType=Oracle.DataAccess.Client.OracleDataAdapter"
MySQL ConnectionString = "Server=serverName; Database=databaseName; Uid=root; Pwd=password; allow user variables = true"
DataProviderString = "AssemblyName={MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d}; ConnectionType=MySql.Data.MySqlClient.MySqlConnection; AdapterType=MySql.Data.MySqlClient.MySqlDataAdapter"
SQLite ConnectionString = "Data Source=databaseName.db; Version=3; Foreign Keys=True; FailIfMissing=True"
DataProviderString = "AssemblyName={System.Data.SQLite, Version=1.0.109.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139}; ConnectionType=System.Data.SQLite.SQLiteConnection; AdapterType=System.Data.SQLite.SQLiteDataAdapter"
SQLite (Mono native driver) ConnectionString = "Data Source=./databaseName.db; Version=3; Foreign Keys=True; FailIfMissing=True"
DataProviderString = "AssemblyName={Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756}; ConnectionType=Mono.Data.Sqlite.SqliteConnection; AdapterType=Mono.Data.Sqlite.SqliteDataAdapter"
Access / OleDB ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=databaseName.mdb"
DataProviderString = "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.OleDb.OleDbConnection; AdapterType=System.Data.OleDb.OleDbDataAdapter"
ODBC Connection ConnectionString = "Driver={SQL Server Native Client 10.0}; Server=serverName; Database=databaseName; Uid=userName; Pwd=password"
DataProviderString = "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.Odbc.OdbcConnection; AdapterType=System.Data.Odbc.OdbcDataAdapter"
Example configuration file that defines connection settings:
C#
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="categorizedSettings" type="GSF.Configuration.CategorizedSettingsSection, GSF.Core" />
  </configSections>
  <categorizedSettings>
    <systemSettings>
      <add name="ConnectionString" value="Data Source=localhost\SQLEXPRESS; Initial Catalog=MyDatabase; Integrated Security=SSPI" description="ADO database connection string" encrypted="false" />
      <add name="DataProviderString" value="AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.SqlClient.SqlConnection; AdapterType=System.Data.SqlClient.SqlDataAdapter" description="ADO database provider string" encrypted="false" />
    </systemSettings>
  </categorizedSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>
See Also