在Linux上使用Mono串連MySQL資料庫

來源:互聯網
上載者:User
我的測試平台是Ubuntu+Mono1.2.4+MySQL5+Connector/Net 5.1.4,其中Mono和MySQL都是使用apt-get方式安裝很方便。MySQL Connector/Net 5.1.4從http://dev.mysql.com/downloads/connector/net/5.1.html 下載Windows Source and Binaries, no installer (ZIP)解壓縮得到MySql.Data.dll。
使用gacutil -i MySql.Data.dll把MySql.Data.dll安裝到Mono的全域群組件目錄下。
具體內容參考http://www.mono-project.com/MySQL的例子。
特別提出來的是我第一次編譯啟動並執行時候出現這樣的錯誤提示:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts
in <0x006c5> MySql.Data.MySqlClient.NativeDriver:Open ()
in <0x00027> MySql.Data.MySqlClient.Driver:Create (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x0008d> MySql.Data.MySqlClient.MySqlPool:CreateNewPooledConnection ()
in <0x001b0> MySql.Data.MySqlClient.MySqlPool:GetPooledConnection ()
in <0x0003f> MySql.Data.MySqlClient.MySqlPool:GetConnection ()
in <0x000e5> MySql.Data.MySqlClient.MySqlPoolManager:GetConnection (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x00050> MySql.Data.MySqlClient.MySqlConnection:Open ()

不思不得其解,後來找到一個國外的論壇,得到這樣的提示:
The most likely cause of this is that MySQL is not configured to accept tcp/ip connections.
See here http://dev.mysql.com/doc/mysql/en/can-not-connect-to-server.html
make
sure your /etc/mysql/my.cnf file does not have the "skip-networking"
feature enabled. This is the default in some installations and disables
tcp/ip connections.
根據提示我把my.cnf中的
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 172.22.60.126
bind-address注釋掉,然後重新啟動mysql伺服器程式sudo /etc/init.d/mysql restart就可以正常串連查詢了。
GOOD Luck!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.