5.2 Creating a Connector/Net Connection String

5.2.1 Opening a Connection
5.2.2 Handling Connection Errors
5.2.3 Using GetSchema on a Connection

The MySqlConnection object is configured using a connection string. A connection string contains several key/value pairs, separated by semicolons. In each key/value pair, the option name and its corresponding value are joined by an equal sign. For the list of option names to use in the connection string, see Chapter 6, Connector/Net Connection String Options Reference.

The following is a sample connection string:


In this example, the MySqlConnection object is configured to connect to a MySQL server at, with a user name of root and a password of 12345. The default database for all statements will be the test database.


Using the '@' symbol for parameters is now the preferred approach, although the old pattern of using '?' is still supported. To avoid conflicts when using the '@' symbol in combination with user variables, see the Allow User Variables connection string option in Chapter 6, Connector/Net Connection String Options Reference. The Old Syntax connection string option has now been deprecated.