How to solve the problem of connecting IBatis.net to MySQL

Source: Internet
Author: User

As I recently conducted a cross-database operation test, I started IBatisNet IBatis. dataMapper.1.6.2/IBatis. dataAccess.1.9.2) + SQL Server2005 was used smoothly, but some problems occurred when IBatisNet + MySQL5.1 was used. After hard work and online collection, I finally solved the problem and solution. I will share them one by one.

Problem description:

1. the error message is "Check the MySQL.

If this problem occurs, download mySQL-connector-net. If you have downloaded and installed it, continue to check the providers of IBatisNet. whether the enabled of the MySQL provider node in the config file is set to "true". If it is set to "true", continue to check the provider, some official configurations use the dynamic link library file version which is very old. You need to modify it manually, for example:

Before modification:

 
 
  1. <provider      
  2.  
  3.       name="MySQL"      
  4.  
  5.       description="MySQL, MySQL provider 1.0.7.30072"      
  6.  
  7.       enabled="false"      
  8.  
  9.       assemblyName="MySQL.Data,   
  10.       Version=1.0.7.30072, Culture=neutral,   
  11.       PublicKeyToken=c5687fc88969c44d" connectionClass="MySQL.Data.MySQLClient.MySQLConnection"      
  12.  
  13.       commandClass="MySQL.Data.MySQLClient.MySQLCommand"      
  14.  
  15.       parameterClass="MySQL.Data.MySQLClient.MySQLParameter"      
  16.  
  17.       parameterDbTypeClass="MySQL.Data.MySQLClient.MySQLDbType"      
  18.  
  19.       parameterDbTypeProperty="MySQLDbType"      
  20.  
  21.       dataAdapterClass="MySQL.Data.MySQLClient.MySQLDataAdapter"      
  22.  
  23.       commandBuilderClass="MySQL.Data.MySQLClient.MySQLCommandBuilder"      
  24.  
  25.       usePositionalParameters="false"      
  26.  
  27.       useParameterPrefixInSQL="true"      
  28.  
  29.       useParameterPrefixInParameter="true"      
  30.  
  31.       parameterPrefix="?"    
  32.  
  33.       allowMARS="false"         
  34.  
  35.   />   
  36.  

After modification (please note that, if it is set to false, the database cannot be connected successfully ):

 
 
  1. <provider    
  2.  
  3.     name="MySQL"    
  4.  
  5.     description="MySQL,   
  6.     MySQL provider V6.3.2.0"    
  7.  
  8.     enabled="true"    
  9.  
  10.     assemblyName="MySQL.Data, Version=6.3.2.0,   
  11.     Culture=neutral, PublicKeyToken=c5687fc88969c44d"   
  12.     connectionClass=  
  13.     "MySQL.Data.MySQLClient.MySQLConnection"    
  14.  
  15.     commandClass=  
  16.     "MySQL.Data.MySQLClient.MySQLCommand"    
  17.  
  18.     parameterClass=  
  19.     "MySQL.Data.MySQLClient.MySQLParameter"    
  20.  
  21.     parameterDbTypeClass=  
  22.     "MySQL.Data.MySQLClient.MySQLDbType"    
  23.  
  24.     parameterDbTypeProperty=  
  25.     "MySQLDbType"    
  26.  
  27.     dataAdapterClass=  
  28.     "MySQL.Data.MySQLClient.MySQLDataAdapter"    
  29.  
  30.     commandBuilderClass=  
  31.     "MySQL.Data.MySQLClient.MySQLCommandBuilder"    
  32.  
  33.     usePositionalParameters="false"    
  34.  
  35.     useParameterPrefixInSQL="true"    
  36.  
  37.     useParameterPrefixInParameter="true"    
  38.  
  39.     parameterPrefix="?"    
  40.  
  41.     allowMARS="false"    
  42.  
  43.   />   
  44.  

2. The error message "Unable to open connection to" MySQL, MySQL provider V6.3.2.0 "is displayed ".

This error may be caused by a problem with the link string of the configuration file specified by the Configure method. Here is my link, which is for your reference only.

 
 
  1. <? Xml version = "1.0" encoding = "UTF-8"?>
  2.  
  3. <SQLMapConfig xmlns =
  4. "Http://ibatis.apache.org/dataMapper" xmlns: xsi =
  5. Http://www.w3.org/2001/XMLSchema-instance>
  6.  
  7. <! -- The above is a fixed format. From here, the following are user configuration items -->
  8.  
  9. <Settings>
  10.  
  11. <! -- This option indicates whether to use the cache. The default value is true. -->
  12.  
  13. <Setting cacheModelsEnabled = "true"/>
  14.  
  15. <! -- When this option is true,
  16. When you call the specified ing, you must always provide the complete name, for example:
  17. QueryForObject ("Namespace. statement. Id ");
  18. -->
  19.  
  20. <Setting useStatementNamespaces = "false"/>
  21.  
  22. </Settings>
  23.  
  24. <! -- Data Driver provides the path and file name of the class configuration file -->
  25.  
  26. <Providers resource = "providers. config"/>
  27.  
  28. <! -- Specify an Attribute source, which is equivalent to setting some attribute variables,
  29. For this file, see the following -->
  30.  
  31. <! -- Specify the data source $ {datasource }$ {database}
  32. $ {Userid }$ {password}
  33. Value defined for DataBase. config -->
  34.  
  35. <Database>
  36.  
  37. <! -- <Provider name = "ByteFx"> </provider>
  38.  
  39. <DataSource name = "IBatisNet"
  40. ConnectionString = "Database = zy_test; Data Source =
  41. Localhost; User Id = root; Password = 1234 "/> -->
  42.  
  43. <Provider name = "MySQL"> </provider>
  44.  
  45. <DataSource name = "IBatisNet"
  46. ConnectionString = "Host = localhost; UserName =
  47. Root; Password = 1234; Database = zy_test; Port = 3306;
  48. CharSet = utf8; Allow Zero Datetime = true "/>
  49.  
  50. </Database>
  51.  
  52. <! -- Specify the location of the mapped file -->
  53.  
  54. <SQLMaps>
  55.  
  56. <! -- From the Assembly
  57.  
  58. <SQLMap embedded = "$ {root} Person. xml, $ {assembly}"/> -->
  59.  
  60. <! -- From file -->
  61.  
  62. <SQLMap resource = "SQLDetailXml/SystemXml/RoleInfo. xml"/>
  63.  
  64. <SQLMap resource = "SQLDetailXml/SystemXml/ModuleInfo. xml"/>
  65.  
  66. <SQLMap resource = "SQLDetailXml/SystemXml/UserInfo. xml"/>
  67.  
  68. </SQLMaps>
  69.  
  70. </SQLMapConfig>
  71.  

3. The error message "Character set 'gbk' is not supported" is displayed.

If this problem occurs, you may have used the MySQL-connector-net version, because the character encoding provided in MySQL Connector 1.07 is limited and the web cannot be found. the encoding type set in config. If there is no gbk, change to MySQL Connector of a later version.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.