首先,下载MySQL Connector/ODBC 3.51 Downloads
下载下来,安装完成后,到控制面板--〉管理工具--〉Data Source(ODBC), 双击,再点击Add按钮,
选择MySQL ODBC 3.51 Driver
之后,弹出连接mysql参数配置窗口,如下
把相应参数填写好之后,点Test,若连接成功,确定就配置好了。
下面是C#代码
Code
//添加命名空间
using System.Data.Odbc;
Code
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strconn = "Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.105;Database=mydb;User=joe; Password=ast;Option=3;";
string sql = "select title,tid from info";
OdbcConnection myConnection = new OdbcConnection(strconn);
OdbcCommand myCommand = new OdbcCommand(sql, myConnection);
myConnection.Open();
DropDownList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DropDownList1.DataTextField = "title";
DropDownList1.DataValueField = "tid";
DropDownList1.DataBind();
myConnection.Close();
}
MySQL Connector/ODBC 3.51 (MyODBC 3.51)
remote database连接mysql
Code
Driver={MySQL ODBC 3.51 Driver};Server=data.domain.com;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;
ps:在visual studio 2003环境下,MySQL Connector/ODBC 5.1,会有如下异常
"ERROR [HY000] [MySQL][ODBC 5.1 Driver]Access denied for user 'ODBC'@'192.168.1.104' (using password: YES)"
本贴测试环境:
OS : windows xp2
开发环境: visual studio 2003 asp.net 1.1
mysql database 所在服务器: Fedora core 9 linux
mysql版本: mysql Ver 14.12 Distrib 5.0.51a, for redhat-linux-gnu (i386) using readline 5.0