Чтобы установить строку подключения odbc в методе, это можно сделать следующим образом:
odbcConnection = new OdbcConnection();
odbcConnection.Connection = "DRIVER = {MySQL ODBC 5.2w Driver};"
+ "SERVER=localhost;PORT=3306;"
+ "DATABASE=dbdemo2;UID=demo-user";
Почему нужно указывать ДРАЙВЕР в фигурных скобках?





Из документации
Свойство OdbcConnection.ConnectionString
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
Gets or sets the string used to open a data source.
...
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.
В этом случае, вероятно, в этом нет необходимости, хотя в добавлении фигурных скобок вреда нет.