mysql connection string for net
2014-04-19 15:30
337 查看
http://dev.mysql.com/doc/connector-net/en/connector-net-connection-options.html
Table 7.1 Connector/Net Connection String Options - General
The following table lists the valid names for options related to connection pooling within the
For more information about connection pooling, see Section 6.4,
“Using Connector/Net with Connection Pooling”.
Table 7.2 Connector/Net Connection String Options - Connection Pooling
Copyright © 2004, 2014, Oracle and/or its affiliates. All rights reserved. Legal
Notices
Previous / Next / Up / Table
of Contents
Not sure what the deal is, but on Linux (Fedora 14) running Mono/.NET, by default LINQ queries have square brackets around field names, which of course breaks any LINQ query.
The documentation says that "Sql Server Mode" is false by default & that this will prevent square brackets from being used (instead of backtics); the opposite is actually true, wtf ;-)
Solution on my end is to set "Sql Server Mode" to true in my connection string params.
Using connector 6.3.6
http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlconnection.html#connector-net-examples-mysqlconnection-connectionstring
The following table lists the valid names for keyword values within the
The following table lists the valid names for connection pooling values within the
For more information about connection pooling, see Connection Pooling for the MySql Data Provider.
When setting keyword or connection pooling values that require a Boolean value, you can use 'yes' instead of 'true', and 'no' instead of 'false'.
socket protocol to communicate with MySQL. Therefore, it does not support the use of an ODBC data source name (DSN) when connecting to MySQL because it does not add an ODBC layer.
should use caution when constructing a connection string based on user input (for example when retrieving user ID and password information from a dialog box, and appending it to the connection string). The application should ensure that a user cannot embed
extra connection string parameters in these values (for example, entering a password as "validpassword;database=somedb" in an attempt to attach to a different database).
Examples
The following example creates a
sets some of its properties
Visual Basic example:
C# example:
Table 7.1 Connector/Net Connection String Options - General
Name | Default | Description |
---|---|---|
Allow Batch, AllowBatch | true | When true, multiple SQL statements can be sent with one command execution. Note: starting with MySQL 4.1.1, batch statements should be separated by the server-defined separator character. Statements sent to earlier versions of MySQL should be separated by ';'. |
Allow User Variables, AllowUserVariables | false | Setting this to trueindicates that the provider expects user variables in the SQL. This option was added in Connector/Net version 5.2.2. |
Allow Zero Datetime, AllowZeroDateTime | false | If set to True, MySqlDataReader.GetValue()returns a MySqlDateTimeobject for date or datetime columns that have disallowed values, such as zero datetime values, and a System.DateTimeobject for valid values. If set to False(the default setting) it causes a System.DateTimeobject to be returned for all valid values and an exception to be thrown for disallowed values, such as zero datetime values. |
Auto Enlist, AutoEnlist | true | If AutoEnlistis set to true, which is the default, a connection opened using TransactionScopeparticipates in this scope, it commits when the scope commits and rolls back if TransactionScopedoes not commit. However, this feature is considered security sensitive and therefore cannot be used in a medium trust environment. |
BlobAsUTF8ExcludePattern | null | A POSIX-style regular expression that matches the names of BLOB columns that do not contain UTF-8 character data. SeeSection 6.16, “Character Set Considerations for Connector/Net” for usage details. |
BlobAsUTF8IncludePattern | null | A POSIX-style regular expression that matches the names of BLOB columns containing UTF-8 character data. SeeSection 6.16, “Character Set Considerations for Connector/Net” for usage details. |
Certificate File, CertificateFile | null | This option specifies the path to a certificate file in PKCS #12 format (.pfx). For an example of usage, see Section 5.7, “Tutorial: Using SSL with MySQL Connector/Net”. Was introduced with 6.2.1. |
Certificate Password, CertificatePassword | null | Specifies a password that is used in conjunction with a certificate specified using the option CertificateFile. For an example of usage, see Section 5.7, “Tutorial: Using SSL with MySQL Connector/Net”. Was introduced with 6.2.1. |
Certificate Store Location, CertificateStoreLocation | null | Enables you to access a certificate held in a personal store, rather than use a certificate file and password combination. For an example of usage, see Section 5.7, “Tutorial: Using SSL with MySQL Connector/Net”. Was introduced with 6.2.1. |
Certificate Thumbprint, CertificateThumbprint | null | Specifies a certificate thumbprint to ensure correct identification of a certificate contained within a personal store. For an example of usage, see Section 5.7, “Tutorial: Using SSL with MySQL Connector/Net”. Was introduced with 6.2.1. |
CharSet, Character Set, CharacterSet | Specifies the character set that should be used to encode all queries sent to the server. Resultsets are still returned in the character set of the result data. | |
Check Parameters, CheckParameters | true | Indicates if stored routine parameters should be checked against the server. |
Command Interceptors, CommandInterceptors | The list of interceptors that can intercept SQL command operations. | |
Connect Timeout, Connection Timeout, ConnectionTimeout | 15 | The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. |
Connect_Attrs | Passes a predefined set of key/value pairs containing connection-specific data items to the server, for application-defined purposes. connector/Net automatically transmits the following attributes: _pid, _client_version, _platform, _program_name, _os, _os_details, and _thread. See Performance Schema Connection Attribute Tables for the Performance Schema tables to query on the server side to make use of these attributes. | |
Convert Zero Datetime, ConvertZeroDateTime | false | True to have MySqlDataReader.GetValue()and MySqlDataReader.GetDateTime()return DateTime.MinValuefor date or datetime columns that have disallowed values. |
Default Command Timeout, DefaultCommandTimeout | 30 | Sets the default value of the command timeout to be used. This does not supersede the individual command timeout property on an individual command object. If you set the command timeout property, that will be used. This option was added in Connector/Net 5.1.4 |
Default Table Cache Age, DefaultTableCacheAge | 60 | Specifies how long a TableDirectresult should be cached, in seconds. For usage information about table caching, seeSection 6.7, “Using Connector/Net with Table Caching”. This option was added in Connector/Net 6.4. |
enableSessionExpireCallback | false | When set to true, causes the session-expiry scanner to raise the session_endevent before deleting the session data stored in the my_aspnet_sessionstable, when a session times out. Enable this option to write additional application-specific cleanup code to handle the session_endevent of the global.asaxclass, before the stored data of the session gets deleted. Within the session_end method, any other required cleanup can be done. This option was added in Connector/Net 6.4.5; it is not yet available in Connector/Net 6.5.x releases. |
Encrypt, UseSSL | false | For Connector/Net 5.0.3 and later, when true, SSL encryption is used for all data sent between the client and server if the server has a certificate installed. Recognized values are true, false, yes, and no. In versions before 5.0.3, this option had no effect. From version 6.2.1, this option is deprecated and is replaced by SSL Mode. The option still works if used. If this option is set to true, it is equivalent to SSL Mode = Preferred. |
Exception Interceptors, ExceptionInterceptors | The list of interceptors that can triage thrownMySqlExceptionexceptions. | |
Functions Return String, FunctionsReturnString | false | Causes the connector to return binary/varbinary values as strings, if they do not have a tablename in the metadata. |
Host, Server, Data Source, DataSource, Address, Addr, Network Address | localhost | The name or network address of the instance of MySQL to which to connect. Multiple hosts can be specified separated by commas. This can be useful where multiple MySQL servers are configured for replication and you are not concerned about the precise server you are connecting to. No attempt is made by the provider to synchronize writes to the database, so take care when using this option. In Unix environment with Mono, this can be a fully qualified path to a MySQL socket file. With this configuration, the Unix socket is used instead of the TCP/IP socket. Currently, only a single socket name can be given, so accessing MySQL in a replicated environment using Unix sockets is not currently supported. |
Ignore Prepare, IgnorePrepare | true | When true, instructs the provider to ignore any calls toMySqlCommand.Prepare(). This option is provided to prevent issues with corruption of the statements when used with server-side prepared statements. If you use server-side prepare statements, set this option to false. This option was added in Connector/Net 5.0.3 and Connector/Net 1.0.9. |
includesecurityasserts, include security asserts | false | Must be set to truewhen using the MySQLClientPermissionsclass in a partial trust environment, with the library installed in the GAC of the hosting environment. This requirement is new for partial-trust applications in Connector/Net 6.6.4 and higher. SeeSection 6.19, “Working with Partial Trust / Medium Trust” for details. |
Initial Catalog, Database | mysql | The case-sensitive name of the database to use initially. |
Interactive, Interactive Session, InteractiveSession | false | If set to true, the client is interactive. An interactive client is one where the server variable CLIENT_INTERACTIVEis set. If an interactive client is set, the wait_timeoutvariable is set to the value of interactive_timeout. The client will then time out after this period of inactivity. For more details, see Server System Variables in the MySQL Reference Manual. |
Integrated Security, IntegratedSecurity | no | Use Windows authentication when connecting to server. By default, it is turned off. To enable, specify a value of yes. (You can also use the value sspias an alternative to yes.) For details, see Section 6.5, “Using the Windows Native Authentication Plugin”. This option was introduced in Connector/Net 6.4.4. |
Keep Alive, Keepalive | 0 | For TCP connections, idle connection time measured in seconds, before the first keepalive packet is sent. A value of 0 indicates that keepalive is not used. |
Logging | false | When true, various pieces of information is output to any configured TraceListeners. See Section 6.14, “Using the MySQL Connector/Net Trace Source Object” for further details. |
Old Guids, OldGuids | false | This option was introduced in Connector/Net 6.1.1. The backend representation of a GUID type was changed fromBINARY(16)to CHAR(36). This was done to allow developers to use the server function UUID()to populate a GUID table - UUID()generates a 36-character string. Developers of older applications can add 'Old Guids=true'to the connection string to use a GUID of data type BINARY(16). |
Old Syntax, OldSyntax, Use Old Syntax, UseOldSyntax | false | This option was deprecated in Connector/Net 5.2.2. All code should now be written using the '@' symbol as the parameter marker. |
Password, pwd | The password for the MySQL account being used. | |
Persist Security Info, PersistSecurityInfo | false | When set to falseor no(strongly recommended), 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. Resetting the connection string resets all connection string values, including the password. Recognized values are true, false, yes, and no. |
Pipe Name, Pipe, PipeName | mysql | When set to the name of a named pipe, theMySqlConnectionattempts to connect to MySQL on that named pipe. This setting only applies to the Windows platform. |
Port | 3306 | The port MySQL is using to listen for connections. This value is ignored if Unix socket is used. |
Procedure Cache Size, ProcedureCacheSize, procedure cache, procedurecache | 25 | Sets the size of the stored procedure cache. By default, Connector/Net stores the metadata (input/output data types) about the last 25 stored procedures used. To disable the stored procedure cache, set the value to zero (0). This option was added in Connector/Net 5.0.2 and Connector/Net 1.0.9. |
Protocol, Connection Protocol, ConnectionProtocol | socket | Specifies the type of connection to make to the server. Values can be: socketor tcpfor a socket connection, pipefor a named pipe connection, unixfor a Unix socket connection, memoryto use MySQL shared memory. |
Replication | false | Indicates if this connection is to use replicated servers. |
Respect Binary Flags, RespectBinaryFlags | true | Setting this option to falsemeans that Connector/Net ignores a column's binary flags as set by the server. This option was added in Connector/Net version 5.1.3. |
Shared Memory Name, SharedMemoryName | MYSQL | The name of the shared memory object to use for communication if the connection protocol is set to memory. |
Sql Server Mode, sqlservermode | false | Allow SQL Server syntax. When set to true, enables Connector/Net to support square brackets around symbols instead of backticks. This enables Visual Studio wizards that bracket symbols with [] to work with Connector/Net. This option incurs a performance hit, so should only be used if necessary. This option was added in version 6.3.1. |
SSL Mode, SslMode | None | This option has the following values: None - do not use SSL. Preferred - use SSL if the server supports it, but allow connection in all cases. Required - Always use SSL. Deny connection if server does not support SSL. VerifyCA - Always use SSL. Validate the CA but tolerate name mismatch. VerifyFull - Always use SSL. Fail if the host name is not correct. This option was introduced in MySQL Connector/Net 6.2.1. |
Table Cache, tablecache, tablecaching | false | Enables or disables caching of TableDirectcommands. A value of trueenables the cache while falsedisables it. For usage information about table caching, see Section 6.7, “Using Connector/Net with Table Caching”. This option was added in Connector/Net 6.4. |
Treat BLOBs as UTF8, TreatBlobsAsUTF8 | false | |
Treat Tiny As Boolean, TreatTinyAsBoolean | true | Setting this value to falsecauses TINYINT(1)to be treated as an INT. See Numeric Type Overview for a further explanation of the TINYINTand BOOLdata types. |
Use Affected Rows, UseAffectedRows | false | When true, the connection reports changed rows instead of found rows. This option was added in Connector/Net version 5.2.6. |
Use Procedure Bodies, UseProcedureBodies, procedure bodies | true | When set to true, the default value, MySQL Connector/Net expects the body of the procedure to be viewable. This enables it to determine the parameter types and order. Set the option to falsewhen the user connecting to the database does not have the SELECTprivileges for the mysql.proc(stored procedures) table, or cannot view INFORMATION_SCHEMA.ROUTINES. In this case, MySQL Connector/Net cannot determine the types and order of the parameters, and must be alerted to this fact by setting this option to false. When set to false, MySQL Connector/Net does not rely on this information being available when the procedure is called. Because MySQL Connector/Net will not be able to determine this information, explicitly set the types of all the parameters before the call and add the parameters to the command in the same order as they appear in the procedure definition. This option was added in MySQL Connector/Net 5.0.4 and MySQL Connector/Net 1.0.10. |
User Id, UserID, Username, Uid, User name, User | The MySQL login account being used. | |
Compress, Use Compression, UseCompression | false | Setting this option to trueenables compression of packets exchanged between the client and the server. This exchange is defined by the MySQL client/server protocol. Compression is used if both client and server support ZLIB compression, and the client has requested compression using this option. A compressed packet header is: packet length (3 bytes), packet number (1 byte), and Uncompressed Packet Length (3 bytes). The Uncompressed Packet Length is the number of bytes in the original, uncompressed packet. If this is zero, the data in this packet has not been compressed. When the compression protocol is in use, either the client or the server may compress packets. However, compression will not occur if the compressed length is greater than the original length. Thus, some packets will contain compressed data while other packets will not. |
Use Usage Advisor, Usage Advisor, UseUsageAdvisor | false | Logs inefficient database operations. |
Use Performance Monitor, UsePerformanceMonitor, userperfmon, perfmon | false | Indicates that performance counters should be updated during execution. |
Connection Pooling Options
The following table lists the valid names for options related to connection pooling within the ConnectionString.
For more information about connection pooling, see Section 6.4,
“Using Connector/Net with Connection Pooling”.
Table 7.2 Connector/Net Connection String Options - Connection Pooling
Name | Default | Description |
---|---|---|
Cache Server Properties, CacheServerProperties | false | Specifies whether server variable settings are updated by a SHOW VARIABLEScommand each time a pooled connection is returned. Enabling this setting speeds up connections in a connection pool environment. Your application is not informed of any changes to configuration variables made by other connections. This option was added in Connector/Net 6.3. |
Connection Lifetime, ConnectionLifeTime | 0 | 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. This is useful in clustered configurations to force load balancing between a running server and a server just brought online. A value of zero (0) causes pooled connections to have the maximum connection timeout. |
Connection Reset, ConnectionReset | false | If true, the connection state is reset when it is retrieved from the pool. The default value of false avoids making an additional server round trip when obtaining a connection, but the connection state is not reset. |
Maximum Pool Size, Max Pool Size, MaximumPoolsize, maxpoolsize(only for Connector/Net 6.7 and later) | 100 | The maximum number of connections allowed in the pool. |
Minimum Pool Size, Min Pool Size, MinimumPoolSize, minpoolsize(only for Connector/Net 6.7 and later) | 0 | The minimum number of connections allowed in the pool. |
Pooling | true | When true, the MySqlConnectionobject is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool. Recognized values are true, false, yes, and no. |
Notices
Previous / Next / Up / Table
of Contents
User Comments
Posted by Noah Cutler on June 11 2011 5:26pm | [Delete] [Edit] |
The documentation says that "Sql Server Mode" is false by default & that this will prevent square brackets from being used (instead of backtics); the opposite is actually true, wtf ;-)
Solution on my end is to set "Sql Server Mode" to true in my connection string params.
Using connector 6.3.6
http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlconnection.html#connector-net-examples-mysqlconnection-connectionstring
The following table lists the valid names for keyword values within the
ConnectionString.
Name | Default | Description |
Connect Timeout, Connection Timeout | 15 | The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. |
Host, Server, Data Source, DataSource, Address, Addr, Network Address | localhost | The name or network address of the instance of MySQL to which to connect. Multiple hosts can be specified separated by &. This can be useful where multiple MySQL servers are configured for replication and you are not concerned about the precise server you are connecting to. No attempt is made by the provider to synchronize writes to the database so care should be taken when using this option. In Unix environment with Mono, this can be a fully qualified path to MySQL socket filename. With this configuration, the Unix socket will be used instead of TCP/IP socket. Currently only a single socket name can be given so accessing MySQL in a replicated environment using Unix sockets is not currently supported. |
Ignore Prepare | true | When true, instructs the provider to ignore any calls to MySqlCommand.Prepare(). This option is provided to prevent issues with corruption of the statements when use with server side prepared statements. If you want to use server-side prepare statements, set this option to false. This option was added in Connector/NET 5.0.3. |
Port | 3306 | The port MySQL is using to listen for connections. Specify -1 for this value to use a named pipe connection (Windows only). This value is ignored if Unix socket is used. |
Protocol | socket | Specifies the type of connection to make to the server.Values can be: socket or tcp for a socket connection pipe for a named pipe connection unix for a Unix socket connection memory to use MySQL shared memory |
CharSet, Character Set | Specifies the character set that should be used to encode all queries sent to the server. Resultsets are still returned in the character set of the data returned. | |
Logging | false | When true, various pieces of information is output to any configured TraceListeners. |
Allow Batch | true | When true, multiple SQL statements can be sent with one command execution. -Note- Starting with MySQL 4.1.1, batch statements should be separated by the server-defined seperator character. Commands sent to earlier versions of MySQL should be seperated with ';'. |
Encrypt | false | For Connector/NET 5.0.3 and later, when true, SSL encryption is used for all data sent between the client and server if the server has a certificate installed. Recognized values are true, false, yes, and no. In versions before 5.0.3, this option had no effect. |
Initial Catalog, Database | mysql | The name of the database to use intially |
Password, pwd | The password for the MySQL account being used. | |
Persist Security Info | false | When set to falseor no(strongly recommended), 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. Resetting the connection string resets all connection string values including the password. Recognized values are true, false, yes, and no. |
User Id, Username, Uid, User name | The MySQL login account being used. | |
Shared Memory Name | MYSQL | The name of the shared memory object to use for communication if the connection protocol is set to memory. |
Allow Zero Datetime | false | True to have MySqlDataReader.GetValue() return a MySqlDateTime for date or datetime columns that have illegal values. False will cause a System.DateTimeobject to be returned for legal values and an exception will be thrown for illegal values. |
Convert Zero Datetime | false | True to have MySqlDataReader.GetValue()and MySqlDataReader.GetDateTime()return DateTime.MinValue for date or datetime columns that have illegal values. |
Old Syntax, OldSyntax | false | Allows use of '@' symbol as a parameter marker. See MySqlCommandfor more info. This is for compatibility only. All future code should be written to use the new '?' parameter marker. |
Pipe Name, Pipe | mysql | When set to the name of a named pipe, the MySqlConnectionwill attempt to connect to MySQL on that named pipe.This settings only applies to the Windows platform. |
ConnectionString.
For more information about connection pooling, see Connection Pooling for the MySql Data Provider.
Name | Default | Description |
Connection Lifetime | 0 | 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 byConnection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online. A value of zero (0) causes pooled connections to have the maximum connection timeout. |
Max Pool Size | 100 | The maximum number of connections allowed in the pool. |
Min Pool Size | 0 | The minimum number of connections allowed in the pool. |
Pooling | true | When true, the MySqlConnectionobject is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool. Recognized values are true, false, yes, and no. |
Reset Pooled Connections, ResetConnections, ResetPooledConnections | true | Specifies whether a ping and a reset should be sent to the server before a pooled connection is returned. Not resetting will yeild faster connection opens but also will not clear out session items such as temp tables. |
Cache Server Configuration, CacheServerConfiguration, CacheServerConfig | false | Specifies whether server variables should be updated when a pooled connection is returned. Turning this one will yeild faster opens but will also not catch any server changes made by other connections. |
NoteThe MySql Data Provider uses the native
socket protocol to communicate with MySQL. Therefore, it does not support the use of an ODBC data source name (DSN) when connecting to MySQL because it does not add an ODBC layer.
CAUTIONIn this release, the application
should use caution when constructing a connection string based on user input (for example when retrieving user ID and password information from a dialog box, and appending it to the connection string). The application should ensure that a user cannot embed
extra connection string parameters in these values (for example, entering a password as "validpassword;database=somedb" in an attempt to attach to a different database).
Examples
The following example creates a
MySqlConnectionand
sets some of its properties
Visual Basic example:
Public Sub CreateConnection() Dim myConnection As New MySqlConnection() myConnection.ConnectionString = "Persist Security Info=False;database=myDB;server=myHost;Connect Timeout=30;user id=myUser; pwd=myPass" myConnection.Open() End Sub 'CreateConnection
C# example:
public void CreateConnection() { MySqlConnection myConnection = new MySqlConnection(); myConnection.ConnectionString = "Persist Security Info=False;database=myDB;server=myHost;Connect Timeout=30;user id=myUser; pwd=myPass"; myConnection.Open(); }
相关文章推荐
- [转]ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
- Abusing MySQL string arithmetic for tiny SQL injections
- Lost connection to MySQL server at 'waiting for initial communication packet', system error: 60 "
- ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
- connection string for Excel/Access 2010
- Navacat for MySQL 创建表后无法输入中文 Incorrect string value:\""
- WebConfig ConnectionStrings Tool For .NET2.0
- PHPnow For ASP&&ASP.NET&&MongoDB&&MySQL支持VC6.0编译器&&MySQL升级
- 连接Ubuntu系统服务器Mysql出错(错误:10061)/Jdbc连接远程数据库出错(java.net.ConnectException: Connection refused: connect)
- Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0
- .net mysql dts 分布式事务 Multiple simultaneous connections or connections with different connection··
- APS.NET_MVC5学习笔记-创建连接字符串(Connection String)并使用SQL Server LocalDB
- SQL Server Connection Strings for ASP.NET Web Applications
- ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
- Mysql连接错误:Lost connection to Mysql server at 'waiting for initial communication packet'
- MySQL 执行插入操作时报1366 - Incorrect string value: '\xE4\xB8\xAD\xE6\x96\x87' for column 'name' at row 1
- Read ConnectionString from web.config in ASP.NET 2.0
- ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
- mysql插入数据报错 Incorrect string value for column
- Mysql 错误1366, "Incorrect string value: '\\xE6\\xB7\\xB1\\xE5\\x85\\xA5...' for column '