MySqlConnection Class |
Namespace: MySql.Data.MySqlClient
The MySqlConnection type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | MySqlConnection |
Initializes a new instance of the MySqlConnection class.
|
![]() ![]() | MySqlConnection(String) |
Initializes a new instance of the MySqlConnection class when given a string containing the connection string.
|
Name | Description | |
---|---|---|
![]() | CanRaiseEvents | Gets a value indicating whether the component can raise an event. (Inherited from Component.) |
![]() ![]() | ConnectionString |
Gets or sets the string used to connect to a MySQL Server database.
(Overrides DbConnectionConnectionString.) |
![]() ![]() | ConnectionTimeout |
Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.
(Overrides DbConnectionConnectionTimeout.) |
![]() | Container | Gets the IContainer that contains the Component. (Inherited from Component.) |
![]() ![]() | Database | Gets the name of the current database or the database to be used after a connection is opened. (Overrides DbConnectionDatabase.) |
![]() | DataSource |
Gets the name of the MySQL server to which to connect.
(Overrides DbConnectionDataSource.) |
![]() | DbProviderFactory | (Overrides DbConnectionDbProviderFactory.) |
![]() | DesignMode | Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.) |
![]() | Events | Gets the list of event handlers that are attached to this Component. (Inherited from Component.) |
![]() | IsPasswordExpired |
Gets a boolean value that indicates whether the password associated to the connection is expired.
|
![]() | ServerThread |
Returns the id of the server thread this connection is executing on
|
![]() ![]() | ServerVersion | Gets a string containing the version of the MySQL server to which the client is connected. (Overrides DbConnectionServerVersion.) |
![]() | Site | (Inherited from Component.) |
![]() ![]() | State | Gets the current state of the connection. (Overrides DbConnectionState.) |
![]() | UseCompression |
Indicates if this connection should use compression when communicating with the server.
|
Name | Description | |
---|---|---|
![]() | BeginDbTransaction | (Overrides DbConnectionBeginDbTransaction(IsolationLevel).) |
![]() ![]() | BeginTransaction | Begins a database transaction. |
![]() | BeginTransaction(IsolationLevel) | Starts a database transaction with the specified isolation level. (Inherited from DbConnection.) |
![]() ![]() | BeginTransaction(IsolationLevel, String) | Begins a database transaction with the specified isolation level. |
![]() | BeginTransactionAsync |
Initiates the asynchronous execution of a transaction.
|
![]() | BeginTransactionAsync(IsolationLevel) |
Asynchronous version of BeginTransaction.
|
![]() | BeginTransactionAsync(CancellationToken) |
Asynchronous version of BeginTransaction.
|
![]() | BeginTransactionAsync(IsolationLevel, CancellationToken) |
Asynchronous version of BeginTransaction.
|
![]() | CancelQuery |
Cancels the query after the specified time interval.
|
![]() ![]() | ChangeDatabase | Changes the current database for an open MySqlConnection. (Overrides DbConnectionChangeDatabase(String).) |
![]() | ChangeDataBaseAsync(String) |
Asynchronous version of the ChangeDataBase method.
|
![]() | ChangeDataBaseAsync(String, CancellationToken) |
Asynchronous version of the ChangeDataBase method.
|
![]() ![]() | ClearAllPools | Clears all connection pools. |
![]() | ClearAllPoolsAsync |
Asynchronous version of the ClearAllPools method.
|
![]() | ClearAllPoolsAsync(CancellationToken) |
Asynchronous version of the ClearAllPools method.
|
![]() ![]() | ClearPool | Empties the connection pool associated with the specified connection. |
![]() | ClearPoolAsync(MySqlConnection) |
Asynchronous version of the ClearPool method.
|
![]() | ClearPoolAsync(MySqlConnection, CancellationToken) |
Asynchronous version of the ClearPool method.
|
![]() | Clone |
Creates a new MySqlConnection object with the exact same ConnectionString value
|
![]() ![]() | Close | Closes the connection to the database. This is the preferred method of closing any open connection. (Overrides DbConnectionClose.) |
![]() | CloseAsync |
Asynchronous version of the Close method.
|
![]() | CloseAsync(CancellationToken) |
Asynchronous version of the Close method.
|
![]() | CreateCommand |
Creates and returns a MySqlCommand object associated with the MySqlConnection.
|
![]() | CreateDbCommand | (Overrides DbConnectionCreateDbCommand.) |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() | Dispose | Releases all resources used by the MySqlConnection |
![]() | Dispose(Boolean) | Releases the unmanaged resources used by the MySqlConnection and optionally releases the managed resources (Overrides ComponentDispose(Boolean).) |
![]() | EnlistTransaction |
Enlists in the specified transaction.
(Overrides DbConnectionEnlistTransaction(Transaction).) |
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | (Overrides ComponentFinalize.) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetSchema |
Returns schema information for the data source of this DbConnection.
(Overrides DbConnectionGetSchema.) |
![]() | GetSchema(String) |
Returns schema information for the data source of this
DbConnection using the specified string for the schema name.
(Overrides DbConnectionGetSchema(String).) |
![]() | GetSchema(String, String) |
Returns schema information for the data source of this DbConnection
using the specified string for the schema name and the specified string array
for the restriction values.
(Overrides DbConnectionGetSchema(String, String).) |
![]() | GetSchemaCollection |
Gets a schema collection based on the provided restriction values.
|
![]() | GetSchemaCollectionAsync(String, String) |
Asynchronous version of the GetSchemaCollection method.
|
![]() | GetSchemaCollectionAsync(String, String, CancellationToken) |
Asynchronous version of the GetSchemaCollection method.
|
![]() | GetService | (Inherited from Component.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | OnStateChange | Raises the StateChange event. (Inherited from DbConnection.) |
![]() ![]() | Open | Opens a database connection with the property settings specified by the ConnectionString. (Overrides DbConnectionOpen.) |
![]() | OpenAsync | An asynchronous version of Open, which opens a database connection with the settings specified by the ConnectionString. This method invokes the virtual method OpenAsync(CancellationToken) with CancellationToken.None. (Inherited from DbConnection.) |
![]() | OpenAsync(CancellationToken) | This is the asynchronous version of Open. Providers should override with an appropriate implementation. The cancellation token can optionally be honored.The default implementation invokes the synchronous Open call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.Do not invoke other methods and properties of the DbConnection object until the returned Task is complete. (Inherited from DbConnection.) |
![]() | Ping |
Pings the server.
|
![]() | ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.) |
Name | Description | |
---|---|---|
![]() | Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.) |
![]() | InfoMessage | Occurs when MySQL returns warnings as a result of executing a command or query. |
![]() | StateChange | Occurs when the state of the event changes. (Inherited from DbConnection.) |
A MySqlConnection object represents a session to a MySQL Server data source. When you create an instance of MySqlConnection, all properties are set to their initial values. For a list of these values, see the MySqlConnection constructor.
If the MySqlConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close or Dispose.
<c> public void InsertRow(string myConnectionString) { // If the connection string is null, use a default. if(myConnectionString == "") { myConnectionString = "Database=Test;Data Source=localhost;User Id=username;Password=pass"; } MySqlConnection myConnection = new MySqlConnection(myConnectionString); string myInsertQuery = "INSERT INTO Orders (id, customerId, amount) Values(1001, 23, 30.66)"; MySqlCommand myCommand = new MySqlCommand(myInsertQuery); myCommand.Connection = myConnection; myConnection.Open(); myCommand.ExecuteNonQuery(); myCommand.Connection.Close(); } </c>