System.Data
1.0.5000.0
2.0.0.0
System.Data.Common.DbConnection
System.ICloneable
System.ComponentModel.DefaultEvent("InfoMessage")
An object represents a unique connection to a data source created by using a connection string or ODBC data source name (DSN). With a client/server database system, it is equivalent to a network connection to the server. Depending on the functionality supported by the native ODBC driver, some methods or properties of an object may not be available.
The object uses native resources such as ODBC environment and connection handles. You should always explicitly close any open objects by calling or Dispose before the object goes out of scope, or by placing the connection within a Using statement. Not doing this leaves the freeing of these native resources to garbage collection. It might not free them immediately. This, in turn, can eventually cause the underlying driver to run out of resources or reach a maximum limit. This has resulted in intermittent failures. For example, you might experience Maximum Connections -related errors while many connections are waiting to be deleted by the garbage collector. Explicitly closing the connections allows for a more efficient use of native resources, enhancing scalability and improving overall application performance.
To deploy high-performance applications, you frequently must use connection pooling. However, when you use the .NET Framework Data Provider for ODBC, you do not have to enable connection pooling because the provider manages this automatically.
If one of the Execute methods of the class causes a fatal (for example, a SQL Server severity level of 20 or greater), the may close. However, the user can reopen the connection and continue.
An application that creates an instance of the object can require all direct and indirect callers to have sufficient permission to the code by setting declarative or imperative security demands. creates security demands by using the object. Users can verify that their code has sufficient permissions by using the object. Users and administrators can also use the Code Access Security Policy Tool (Caspol.exe) to modify security policy at the computer, user, and enterprise levels. For more information, see Code Access Security and ADO.NET.
For more information about handling warning and informational messages from the data source, see Working with Connection Events.
Represents an open connection to a data source.
Constructor
When a new instance of is created, the write-only and read-only properties are set to the following initial values unless they are specifically set using their associated keywords in the property.
-
Properties
Initial value
-
empty string ("")
-
15
-
empty string ("")
You can change the value for these properties only by using the property.
Initializes a new instance of the class.
1.0.5000.0
2.0.0.0
Constructor
When a new instance of is created, the write-only and read-only properties are set to the following initial values unless they are specifically set using their associated keywords in the property.
-
Properties
Initial value
-
-
15
-
empty string ("")
You can change the value for these properties only by using the property.
Initializes a new instance of the class with the specified connection string.
The connection used to open the data source.
1.0.5000.0
2.0.0.0
Method
System.Data.Common.DbTransaction
To be added.
To be added.
To be added.
To be added.
2.0.0.0
Method
System.Data.Odbc.OdbcTransaction
To commit or roll back the transaction, you must explicitly use the or methods.
To make sure that the .NET Framework Data Provider for ODBC transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.
If you do not specify an isolation level, the isolation level will be determined by the driver being used. To specify an isolation level with the method, use the overload that takes the parameter.
Starts a transaction at the data source.
An object representing the new transaction.
1.0.5000.0
2.0.0.0
Method
System.Data.Odbc.OdbcTransaction
To commit or roll back the transaction, you must explicitly use the or methods.
To make sure that the .NET Framework Data Provider for ODBC transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.
Starts a transaction at the data source with the specified value.
An object representing the new transaction.
The transaction isolation level for this connection. If you do not specify an isolation level, the default isolation level for the driver is used.
1.0.5000.0
2.0.0.0
Method
System.Void
The parameter must contain a valid database name, and cannot contain a null value, an empty string (""), or a string with only blank characters.
Changes the current database associated with an open .
The database name.
1.0.5000.0
2.0.0.0
Method
System.Void
The method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled. If is called while handling a event, no additional events are fired.
An application can call more than one time without generating an exception.
When you use the .NET Framework Data Provider for ODBC, you do not have to enable connection pooling because the ODBC Driver Manager manages this automatically. For more information about how to enable and disabling connection pooling, see the Microsoft Open Database Connectivity (ODBC) documentation.
Do not call or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, you should only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition. For more information, see Garbage Collection.
Closes the connection to the data source.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.RecommendedAsConfigurable(true)
System.ComponentModel.Editor("Microsoft.VSDesigner.Data.Odbc.Design.OdbcConnectionStringEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.All)
System.ComponentModel.DefaultValue("")
System.String
To be added.
The property is designed to match ODBC connection string format as closely as possible. The can be set only when the connection is closed, and as soon as it is set it is passed, unchanged, to the Driver Manager and the underlying driver. Therefore, the syntax for the must exactly match what the Driver Manager and underlying driver support.
You can use the property to connect to a variety of data sources. This includes an ODBC data source name (DSN). The following example illustrates several possible connection strings.
"Driver={SQL Server};Server=(local);Trusted_Connection=Yes;Database=AdventureWorks;"
"Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;Persist Security Info=False;Trusted_Connection=Yes"
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\Northwind.mdb"
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls"
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin"
"DSN=dsnname"
The .NET Framework Data Provider for ODBC does not support the Persist Security Info keyword that is supported by other .NET Framework data providers. However, the property behaves as if Persist Security Info were set to false. This means that you cannot retrieve the password from the property if the connection has been opened. When the property is read from an object that has been opened, the connection string is returned minus the password. You cannot change this behavior; therefore, if the application requires the password, store it separately before calling .
Many of the settings specified in the string have corresponding read-only properties (for example, Server=(local), which corresponds to the property). These properties are updated after the connection is opened, except when an error is detected. In this case, none of the properties are updated. properties (such as ) return only default settings or those settings specified in the .
In the Microsoft .NET Framework version 1.0, validation of the connection string does not occur until an application calls the method. It is the responsibility of the underlying ODBC driver to validate the connection string. If the connection string contains invalid or unsupported properties, the driver may raise an at run time.
However, in the .NET Framework version 1.1 and later versions, some basic validation of the connection string occurs as soon as you set the property. At that time, the data provider verifies that the connection string meets the "keyword=value;..." format, but it does not verify whether keywords or values are valid. The remaining verification is performed by the underlying ODBC driver when the application calls the method.
An ODBC connection string has the following syntax:
connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string
empty-string ::=
attribute ::= attribute-keyword=attribute-value | DRIVER=[{]attribute-value[}]
attribute-keyword ::= DSN | UID | PWD
| driver-defined-attribute-keyword
attribute-value ::= character-string
driver-defined-attribute-keyword ::= identifier
where has zero or more characters; has one or more characters; is not case sensitive; can be case sensitive; and the value of the DSN keyword does not consist only of blanks.
Because of connection string and initialization file grammar, keywords and attribute values should be avoided that contain the characters []{}(),;?*=!@ not enclosed with braces. The value of the DSN keyword cannot consist only of blanks and should not contain leading blanks. Because of the grammar of the system information, keywords and data source names cannot contain the backslash (\) character.
Applications do not have to add braces around the attribute value after the Driver keyword unless the attribute contains a semicolon (;), in which case the braces are required. If the attribute value that the driver receives includes braces, the driver should not remove them but they should be part of the returned connection string.
A DSN or connection string value enclosed with braces ({}) that contains any of the characters []{}(),;?*=!@ is passed intact to the driver. However, when you use these characters in a keyword, the Driver Manager returns an error when you work with file DSNs, but passes the connection string to the driver for regular connection strings. Avoid using embedded braces in a keyword value.
The connection string may include any number of driver-defined keywords. Because the DRIVER keyword does not use information from the system, the driver must define enough keywords so that a driver can connect to a data source using only the information in the connection string. The driver defines which keywords are required to connect to the data source.
If any keywords are repeated in the connection string, there is no guarantee which value will be selected.
If an ODBC driver supports connection strings longer than 1024 characters, you can use a data source name (DSN) to exceed the maximum length limitation.
Gets or sets the string used to open a data source.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.ComponentModel.DefaultValue(15)
System.Int32
To be added.
Unlike the .NET Framework data providers for SQL Server and OLE DB, the .NET Framework Data Provider for ODBC does not support setting this property as a connection string value, because it is not a valid ODBC connection keyword. To specify a connection time-out, set the property before calling . This is equivalent to setting the ODBC SQLSetConnectAttr SQL_ATTR_LOGIN_TIMOUT attribute.
Gets or sets the time to wait while trying to establish a connection before terminating the attempt and generating an error.
1.0.5000.0
2.0.0.0
Method
System.Data.Odbc.OdbcCommand
To be added.
Creates and returns an object associated with the .
An object.
1.0.5000.0
2.0.0.0
Method
System.Data.Common.DbCommand
To be added.
To be added.
To be added.
2.0.0.0
Property
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.String
To be added.
At first, the property is set in the connection string. The property can be updated by using the method. If you change the current database using an SQL statement or the method, an informational message is sent and then the property is updated.
Retrieving the property is equivalent to calling the ODBC function SQLGetInfo with the parameter set to SQL_ATTR_CURRENT_CATALOG.
Gets the name of the current database or the database to be used after a connection is opened.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.Browsable(false)
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.String
To be added.
Retrieving the property is equivalent to calling the ODBC function SQLGetInfo with the parameter set to SQL_SERVER_NAME.
Gets the server name or file name of the data source.
1.0.5000.0
2.0.0.0
Method
System.Void
To be added.
To be added.
To be added.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.ComponentModel.Browsable(false)
System.String
To be added.
Retrieving the property is equivalent to calling the ODBC function SQLGetInfo with the parameter set to SQL_DRIVER_NAME.
Gets the name of the ODBC driver specified for the current connection.
1.0.5000.0
2.0.0.0
Method
System.Void
New in ADO.NET 2.0 is support for using the method to enlist in a distributed transaction. Because it enlists a connection in a instance, EnlistTransaction takes advantage of functionality available in the namespace for managing distributed transactions, making it preferable to EnlistDistributedTransaction for this purpose. For more information, see Performing a Distributed Transaction.
You can continue to enlist in an existing distributed transaction using the method if auto-enlistment is disabled. Enlisting in an existing distributed transaction makes sure that, if the transaction is committed or rolled back, modifications made by the code at the data source are also committed or rolled back. For more information about distributed transactions, see Performing a Distributed Transaction.
returns an exception if the has already started a transaction using . However, if the transaction is a local transaction started at the data source (for example, by explicitly executing the BEGIN TRANSACTION statement using an object), rolls back the local transaction and enlists in the existing distributed transaction as requested. You will not receive notice that the local transaction was rolled back, and are responsible for managing any local transactions not started using .
Enlists in the specified transaction as a distributed transaction.
A reference to an existing in which to enlist.
1.0.5000.0
2.0.0.0
Method
2.0.0.0
System.Void
New in ADO.NET 2.0 is support for using the method to enlist in a distributed transaction. Because it enlists a connection in a instance, EnlistTransaction takes advantage of functionality available in the namespace for managing distributed transactions, making it preferable to EnlistDistributedTransaction, which uses a System.EnterpriseServices.ITransaction object. It also has slightly different semantics: once a connection is explicitly enlisted on a transaction, it cannot be unenlisted or enlisted in another transaction until the first transaction finishes. For more information about distributed transactions, see Performing a Distributed Transaction.
Enlists in the specified transaction as a distributed transaction.
A reference to an existing in which to enlist.
Method
2.0.0.0
System.Data.DataTable
To be added.
Returns schema information for the data source of this .
A that contains schema information.
Method
2.0.0.0
System.Data.DataTable
When is null, the contains information about all available metadata and any restrictions.
All restrictions that apply to the SQLStatistics method also apply to the ODBCConnection.GetSchema("indexes") collection.
Returns schema information for the data source of this using the specified name for the schema name.
A that contains schema information.
Specifies the name of the schema to return.
Method
2.0.0.0
System.Data.DataTable
When is specified as null, the contains information about all the metadata that is available, and its restrictions.
The parameter can supply n depth of values which are specified by the restrictions collection for a specific collection. In order to set values on a given restriction, and not set the values of other restrictions, you must set the preceding restrictions to null and then put the appropriate value in for the restriction that you would like to specify a value for.
An example of this is the "Tables" collection. If the "Tables" collection has three restrictions (database, owner, and table name), and you want to get back only the tables associated with the owner "Carl," then you would need to pass in at least the following values: null, "Carl". If a restriction value is not passed in, the default values are used for that restriction. This is the same mapping as passing in null, which is different from passing in an empty string for the parameter value. In that case, the empty string ("") is considered to be the value for the specified parameter.
All restrictions that apply to SQLStatistics method will apply to the ODBCConnection.GetSchema("indexes") collection.
Returns schema information for the data source of this using the specified string for the schema name and the specified string array for the restriction values.
A that contains schema information.
Specifies the name of the schema to return.
Specifies a set of restriction values for the requested schema.
Event
System.Data.Odbc.OdbcInfoMessageEventHandler
Clients that want to process warnings or informational messages sent by the server should create an delegate to listen to this event.
Occurs when the ODBC driver sends a warning or an informational message.
1.0.5000.0
2.0.0.0
Method
System.Void
The draws an open connection from the connection pool if one is available. Otherwise, it establishes a new connection to the data source.
If the goes out of scope, the connection it represents does not close automatically. Therefore, you must explicitly close the connection by calling , Dispose, or by placing the connection within a Using statement.
Opens a connection to a data source with the property settings specified by the .
1.0.5000.0
2.0.0.0
Method
System.Void
ReleaseObjectPool can be called to release the ODBC environment handle. You might want to call this method if, for example, the connection object will not be used again. When all connections in the environment are closed, the environment can be disposed. Note that calling the method alone does not actually release the active connections that exist in the environment.
The following must occur before the environment is finally disposed:
-
Call to release the object from the environment.
-
Allow each connection object to time out.
-
Call .
-
Invoke garbage collection.
Conversely, if you call on all active connections, and invoke garbage collection, but do not call , the resources reserved for the environment remain available.
After an environment handle is released, a request for a new creates a new environment.
Indicates that the ODBC Driver Manager environment handle can be released when the last underlying connection is released.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.Browsable(false)
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.String
To be added.
If is not supported by the underlying ODBC driver, an empty string ("") is returned.
The property takes the form '##.##.####,' where the first two digits are the major version, the next two digits are the minor version, and the last four digits are the release version. The driver must render the product version in this form but can also append the product-specific version as a string (for example, "04.01.0000 Rdb 4.1"). This string takes the form 'major.minor.build' where major and minor are exactly two digits and build is exactly four digits.
Gets a string that contains the version of the server to which the client is connected.
1.0.5000.0
2.0.0.0
Property
System.ComponentModel.Browsable(false)
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)
System.Data.ConnectionState
To be added.
The following are allowed state changes:
-
From Closed to Open, using the method.
-
From Open to Closed, using either the or Dispose method.
Calling the property on an open connection increases application overhead because each such call causes a SQL_ATTR_CONNECTION_DEAD call to the underlying ODBC driver to determine whether the connection is still valid.
Gets the current state of the connection.
1.0.5000.0
2.0.0.0
Event
1.0.5000.0
System.Data.StateChangeEventHandler
To be added.
To be added.
Method
1.0.5000.0
System.Data.IDbTransaction
To be added.
To be added.
To be added.
Method
1.0.5000.0
System.Data.IDbTransaction
To be added.
To be added.
To be added.
To be added.
Method
1.0.5000.0
System.Data.IDbCommand
To be added.
To be added.
To be added.
Method
1.0.5000.0
2.0.0.0
System.Object
This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.
For a description of this member, see .
A new that is a copy of this instance.