XNIU’s space

August 15, 2007

MySQL connection string

Filed under: Tech — xniu @ 12:16 pm

Some information about MySQL connection string for .NET driver (MsQL connector/NET):

For detail see: http://dev.mysql.com/doc/refman/5.0/en/connector-net-examples-mysqlconnection.html

Examples:

– Persist Security Info=False; Username=user; Password=pass; database=test1; server=localhost; Connect Timeout=30

– database=myDB; server=/var/lib/mysql/mysql.sock; user id=myUser; pwd=myPass

Some points:

– The ConnectionString property can be set only when the connection is closed. Many of the connection string values have corresponding read-only 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.

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

– If a specific keyword in a keyword=value pair occurs multiple times in a connection string, the last occurrence listed is used in the value set.

– Keywords are not case sensitive.

Frequently used keyword:

– Server/Host/Data Source/Address/Addr: The name or network address of the instance of MySQL to which to connect. Default: localhost.

– Connect Timeout: The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. Default: 15.

– Initial Catalog/Database: The name of the database to use intially. Default: mysql.

– User Id/Uid/User name/Username: The MySQL login account being used.

– Password/Pwd: The password for the MySQL account being used.

(P.S. Windows live writer really sucks!)

Create a free website or blog at WordPress.com.