MySQL ODBC Driver:
安裝完成後,便可在ODBC上查詢到值:
PS:如果不清楚版本,那就32與64都安裝。
程式:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public DataTable GetMyDbList() | |
{ | |
OdbcConnection conn; | |
OdbcDataAdapter ap; | |
DataSet ds = new DataSet(); | |
string constr = "DRIVER={MySQL ODBC 5.2 ANSI Driver};SERVER=localhost;DATABASE=test;UID=root;PWD=;OPTION=3"; | |
conn = new OdbcConnection(constr); | |
conn.Open(); | |
string cmdstr = "select * from mydb;"; | |
ap = new OdbcDataAdapter(cmdstr, conn); | |
ap.Fill(ds); | |
return ds.Table[0]; | |
} |
因為DRIVER安裝版本不同,名稱也會有所不同,
DRIVER={MySQL ODBC 5.2 ANSI Driver},紅色部分就是安裝後ODBC上顯示的名稱。以上圖為例,可表示為:
DRIVER={MySQL ODBC 5.2 ANSI Driver}
DRIVER={MySQL ODBC 5.2 Unicode Driver}
部署IIS注意事項:
- 測試 OS:WIN7或以上(64位元環境)
- 若是安裝的DRIVER版本為32位元,需要將應用程式集區的[啟用32位元應用程式]屬性改為True;64位元則使用預設值(False)。