Odbc连接字符串
OdbcConnection String
要在方法中建立 odbc 连接字符串,可以按以下方式进行:
odbcConnection = new OdbcConnection();
odbcConnection.Connection = "DRIVER={MySQL ODBC 5.2w Driver};"
+ "SERVER=localhost;PORT=3306;"
+ "DATABASE=dbdemo2;UID=demo-user";
为什么需要在大括号中提及 DRIVER?
来自文档
OdbcConnection.ConnectionString Property
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.
在这种情况下它可能不需要它,尽管添加大括号没有坏处
要在方法中建立 odbc 连接字符串,可以按以下方式进行:
odbcConnection = new OdbcConnection();
odbcConnection.Connection = "DRIVER={MySQL ODBC 5.2w Driver};"
+ "SERVER=localhost;PORT=3306;"
+ "DATABASE=dbdemo2;UID=demo-user";
为什么需要在大括号中提及 DRIVER?
来自文档
OdbcConnection.ConnectionString Property
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.
在这种情况下它可能不需要它,尽管添加大括号没有坏处