sqlconnection mysql_ASP.NET使用SqlConnection连接MySQL

这是保存在中的连接字符串web.config:

这是连接到数据库的代码:

protected bool CheckPasswordBySqlServer(string strEmail, string strPsw)

{

if (strEmail.ToLower() == "admin")

{

return false;

}

string str = "select id,Rank,RankEnc,ParentUser,Company from tbl_User where userName=@UserName and password1=@password";

private string strConn = ConfigurationManager.AppSettings["conn"].ToString();

SqlConnection sqlConnection = new SqlConnection(strConn);

bool flag = false;

try

{

try

{

sqlConnection.Open();

SqlCommand sqlCommand = new SqlCommand(str, sqlConnection);

sqlCommand.Parameters.AddWithValue("UserName", strEmail);

sqlCommand.Parameters.AddWithValue("Password", strPsw);

SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

if (!sqlDataReader.Read())

{

flag = false;

}

else

{

this.Session["UserName"] = strEmail;

this.Session["Password"] = strPsw;

this.Session["LoginType"] = "Group";

this.Session["FullName"] = sqlDataReader["Company"].ToString();

if (FormsAuthentication.HashPasswordForStoringInConfigFile(string.Concat(strEmail, (char)43, sqlDataReader["Rank"].ToString()).ToLower(), "MD5") != sqlDataReader["RankEnc"].ToString().Trim())

{

flag = false;

}

this.Session["ClientID"] = sqlDataReader["id"].ToString();

this.Session["MyLanguage"] = base.Request.Cookies["Language"].Value;

this.Session["ParentUser"] = sqlDataReader["ParentUser"].ToString().Trim();

this.Session["Rank"] = sqlDataReader["Rank"].ToString();

this.Session["strConnection"] = this.strConn;

flag = true;

}

sqlDataReader.Close();

}

catch (Exception exception)

{

this.SetlblInfoHtml(exception.Message);

}

}

finally

{

sqlConnection.Close();

}

return flag;

}

但是它无法连接MySQL,并返回以下错误:

System.ArgumentException: Keyword not supported: 'driver'. at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) at System.Data.SqlClient.SqlConnection..ctor(String connectionString) at Source_LoginFrm.CheckPasswordBySqlServer(String strEmail, String strPsw) at Source_LoginFrm.btnLogin_Click(String strLang)

是否可以使用SqlConnection连接MySQL数据库?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值