VS 2010中的MySQL连接 [英] Mysql connection in VS 2010
问题描述
大家好,
我正在使用c#语言和后端作为mysql在asp.net中制作一个项目.我已经安装了vs2010和mysql,还安装了vs2010的mysqlconnector.
我已经安装了mysql-5.0
和mysqlconnector版本-6.3.9
我可以在vs2010中访问mysql db,也可以从vs中获取其连接属性.我得到的连接字符串为:
Hello everyone,
I am making one project in asp.net using c# language and backend as mysql. I have installed vs2010 and mysql and also mysqlconnector for vs2010.
I have installed mysql - 5.0
and mysqlconnector version -6.3.9
I can access mysql db in vs2010 and also could get its connection properties from vs. I got connection string as :
<connectionStrings>
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer" connectionString="server=localhost;User Id=root;Persist Security Info=True;database=helpdesk;password=sa" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
我可以使用相同的server = localhost,用户标识为"root",密码为"sa",从vs2010的服务器浏览器访问数据库.
但是当我从代码访问连接字符串时,它给了我以下错误:
I could access the db from server explorer of vs2010 using same server = localhost , userid as "root" and password as "sa".
but when i access connection string from code it is giving me error of :
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
我的代码是:
my code is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Odbc;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
public OdbcCommand cmd = new OdbcCommand();
public OdbcConnection cn = new OdbcConnection();
public OdbcDataAdapter da = new OdbcDataAdapter();
public DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
cn.ConnectionString = ConfigurationManager.ConnectionStrings["LocalMySqlServer"].ToString();
}
protected void btnConnect_Click(object sender, EventArgs e)
{
cn.Open();
string query = "select * from login";
cmd = new OdbcCommand(query, cn);
da = new OdbcDataAdapter(cmd);
da.Fill(ds);
}
}
请帮帮我...
谢谢&问候,
Krunal Panchal
Please help me out ...
Thanks & Regards,
Krunal Panchal
推荐答案
查看以下线程讨论是否有帮助:
错误:[Microsoft] [ODBC驱动程序管理员]找不到数据源名称,也未指定默认驱动程序.. [ ^ ]
未找到数据源名称且未指定默认驱动程序 [ ^ ]
基于它们,您的连接字符串缺少ODBC连接所需的驱动程序"信息.指定DSN名称.
有关完整的详细信息,请单击此处:连接字符串 [
See if following thread discussion helps:
ERROR : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified..[^]
Data source name not found and no default driver specified[^]
Based on them, your connection string is missing ''Driver'' information which is needed for an ODBC connection. Specify the DSN name.
For complete details, look here: Connection String[^]!
ODBC即将淘汰.在64位系统上,必须确保安装了与您的应用程序匹配的版本(32位或64位).
更好地使用MySql.Data.MySqlClient
命名空间中的类,例如MySqlConnection
,MySqlCommand
等.
ODBC is about to become obsolete. And on 64bit systems, you have to make sure that a version matching your application is installed (32bit or 64bit).
Better use the classes fromMySql.Data.MySqlClient
namespace, e.g.MySqlConnection
,MySqlCommand
etc.
是的Bernhard Hiller是正确的...使用MYSql.Data.MySqlClient ..
下载MYSql.data
http://dev.mysql.com/downloads/connector/net/6.0.html [ ^ ]
从此链接下载此表格
ye Bernhard Hiller is correct ... use MYSql.Data.MySqlClient..
download the MYSql.data
http://dev.mysql.com/downloads/connector/net/6.0.html[^]
download this form this link
这篇关于VS 2010中的MySQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!