dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlConnection Class / ConnectionString Property
Example

In This Topic
    ConnectionString Property (MySqlConnection)
    In This Topic
    Gets or sets the string used to open a MySQL connection.
    Syntax
    'Declaration
     
    Public Overrides Property ConnectionString As String
    public override string ConnectionString {get; set;}

    Property Value

    The connection string that includes the parameters needed to establish the initial connection. The default value is an empty string ("").
    Remarks
    When ConnectionString property is assigned a value, connection closes. Many of the connection string values have corresponding properties. When the connection string is set, all of these properties are updated, except when an error is detected. In this case, none of the properties are updated. MySqlConnection properties return only those settings contained in the ConnectionString.

    Resetting the ConnectionString on a closed connection resets all connection string values (and related properties) including the password. For example, if you set a connection string that includes "User Id=test", and then reset the connection string to "Data Source=localhost", the UserId property is no longer set to test.

    The connection string is parsed immediately after being set. If errors in syntax are found when parsing, a runtime exception, such as System.ArgumentException, is generated. Other errors can be found only when an attempt is made to Open the connection.

    The ConnectionString is similar to an OLE DB connection string. Values may be delimited by single or double quotes, (for example, name='value' or name="value"). Either single or double quotes may be used within a connection string by using the other delimiter, for example, name="value's" or name= 'value"s', but not name= 'value's' or name= ""value"". All blank characters, except those placed within a value or within quotes, are ignored. Keyword value pairs must be separated by a semicolon (;). If a semicolon is part of a value, it also must be delimited by quotes. No escape sequences are supported. The value type is irrelevant. Names are not case sensitive. Arguments names may occur only once in the connection string.

    The following table lists the valid names for values within the ConnectionString.

    Name Description
    Binary As Guid Determines if the provider should treat BINARY(16) columns as guid. Default value is false.
    Binary Uuid Order Determines if the provider should treat BINARY(16) columns as guid in the MySQL UUID_TO_BIN format or in the .NET Guid format. Applied only if the Binary As Guid parameter is set to true. Default value is false, which means .NET Guid format.
    Character Set A character set used by the client. Actually, if this property is enabled, then the "SET NAMES <Charset>" query is executed on establishing a connection. Default value is an empty string. That means there is no action performed with charset on the client and on the server. You can set the Charset property value to 'auto'. In this case, the server asks for the charset and sets the appropriate charset on the client.
    Compress If true, enables transferred data compression. The default value is false.
    Connection Lifetime When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. The default value is 0 (connection always returns to pool).
    Connect Timeout -or- Connection Timeout The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. The default value is 15.
    Data Source -or- Host -or- Server The name or IP address of host of MySQL database to which to connect.
    Database The name of the database.
    Default Auth Plugin The name of the authentication plugin. Applicable only when connecting through the MySQL client library version 5.5 or later.
    Default Command Timeout The time in seconds to wait while trying to execute a command before terminating the attempt and generating an error. 0 indicates no limit.
    Default FetchAll Default value of the FetchAll property of MySqlCommand instances, created via the CreateCommand method. If the FetchAll mode is enabled, MySqlDataReader object retrieves all the querried data from the server on execution.
    Direct If true, by default, allows not to use MySQL client library (libmysql.dll) to access MySQL server.
    Disable Charset Sending Enables or disables explicit charset resetting for the session taken from a pool.
    Embedded If true, allows to use Embedded MySQL server. The default value is false
    Enlist Determines whether the connection is automatically enlisted in the current distributed transaction. The default value is true. This parameter is not available in Mobile Edition. This parameter is also not supported in the .NET Standard 1.3 compatible assembly.
    FoundRows Specifies whether the provider will return the number of rows matched by the WHERE condition of the UPDATE statement instead of the rows actually changed as the number of changed rows.
    HTTP Base64 Specifies whether to encode data to MIME base64 format before sending them with the POST Request when using HTTP Tunneling.
    HTTP Content Length Specifies the Content-Length HTTP header parameter. This is the size of message body in bytes for both client and server.
    HTTP Host Specifies the host name or IP address of HTTP tunnel server.
    HTTP Keep Alive Specifies the timeout in seconds to send Keep-Alive HTTP packets.
    HTTP Max Connection Age Specifies the maximum connection age in seconds after which the tunnel will be closed.
    HTTP Password Specifies the password for HTTP authorization.
    HTTP Port Specifies the port number of HTTP tunnel server.
    HTTP Strict Content Length Specifies whether data padding should be enabled when message size is smaller than MySqlHttpOptions.ContentLength.
    HTTP Url Specifies url of the tunneling PHP script. For example, if the script is in the server root, the url can be the following: http://localhost/tunnel.php.
    HTTP User Specifies the user name for HTTP authorization.
    Ignore Prepare Specifies whether the provider must ignore all MySqlCommand.Prepare calls. Default value is false.
    Initialization Command Specifies a database-specific command that should be executed immediately after establishing the connection.
    Keep Alive Specifies whether to send TCP keep-alive packets and the interval at which they are sent in seconds. Default value is 0, which means that the packets are not sent.
    License Key Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information.
    Max Pool Size The maximum number of connections allowed in the pool. Setting the Max Pool Size value of the ConnectionString can affect performance. The default value is 100.
    Min Pool Size The minimum number of connections allowed in the pool. The default value is 0.
    Password The password for the account.
    Persist Security Info Indicates if security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state.
    Plugin Dir The directory where the plugin is located. Applicable only when connecting through the MySQL client library version 5.5 or later.
    Pooling If true, by default, the MySqlConnection object is drawn from the appropriate pool or is created and added to the appropriate pool.
    Port The port of MySQL database to which to connect. The default value is 3306.
    Protocol The type of the network protocol which will be used to access to MySQL server. The default value is MySqlProtocol.Tcp.
    Proxy Host The host name or IP address of proxy server.
    Proxy Password The password for the proxy server account.
    Proxy Port The port number of the proxy server. The default value is 3128.
    Proxy User The proxy server account name.
    Server Parameters

    Specifies command-line argument for launching MySQL embedded server. Usually used to provide path to files used by server and path to folder where data files reside. For instance:

    Server Parameters=\"--basedir=d:/servers/embedded/;--datadir=d:/servers/embedded/data/;\"

    SQL Modes The value of MySQL sql_mode system variable to be set for the session. You can find the list of the available values and more information in MySQL documentation.
    SSH Authentication Type Client authentication method. See Devart.Common.SshAuthenticationType for additional information.
    SSH Cipher List List of ciphers that client agrees to use. See MySqlConnectionStringBuilder.SshCipherList for additional information.
    SSH Host Name or ip address of SSH server.
    SSH Host Key The location of the public key on the client side to verify the server host key during establishing connection.
    SSH Passphrase Passphrase for the client key.
    SSH Password User password on SSH server.
    SSH Port Number of port on SSH server to connect.
    SSH Private Key Location of the private key to use.
    SSH Strict Host Key Check Indicates whether the host key is verified during establishing connection.
    SSH User User id on SSH server.
    SSL CA Cert Location of authority certificate.
    SSL Cert Location of client certificate.
    SSL Cipher List List of ciphers that client agrees to use.
    SSL Key Location of user's private key.
    SSL TLS Protocol The preferred TLS protocol version, reported to the server when establishing a secure connection.
    Tiny As Boolean Specifies whether the provider should treat TINYINT(1) columns as boolean. Default value is false.
    Transaction Scope Local If there are several connections with the same connection string (which includes "Transaction Scope Local=true;") within a scope of TransactionScope, our provider will use only one connection internally. The default value is false. Not available in Mobile Edition. This parameter is also not supported in the .NET Standard 1.3 compatible assembly.
    Unicode Sets client charset to utf8mb4 for MySQL 5.5.3 and higher or to utf8 for MySQL versions lower than 5.5.3 and converts client data according to this charset.
    User ID -or- User The MySQL login account.
    Validate Connection Specifies whether to validate connections that are being got from the pool.
    Example
    The following example creates a MySqlConnection and sets some of its properties in the connection string.
    public void CreateMySqlConnection()
    {
      string myConnString1 = 
         "User Id=root;Host=localhost;Database=Test;";
      MySqlConnection myConnection1 = new MySqlConnection(myConnString1);
      myConnection1.Open();
    }
    Public Sub CreateMySqlConnection()
      Dim myConnString1 As String = _
          "User Id=root;Host=localhost;Database=Test;"
      Dim myConnection1 As New MySqlConnection(myConnString1)
      myConnection1.Open()
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also