Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
算术运算导致溢出错误c#_C#_Exception Handling_Try Catch_Overflowexception - Fatal编程技术网

算术运算导致溢出错误c#

算术运算导致溢出错误c#,c#,exception-handling,try-catch,overflowexception,C#,Exception Handling,Try Catch,Overflowexception,您好,我正在使用c#构建一个应用程序来连接到远程mysql服务器 代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Form

您好,我正在使用c#构建一个应用程序来连接到远程mysql服务器

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        } 

        private void button1_Click(object sender, EventArgs e)
        {
            if (tryLogin(textBox1.Text, textBox2.Text) == true)
            {
                MessageBox.Show("Authed!");
            }
            else
            {
                MessageBox.Show("Auth Failure.");

            }

        }
        public bool tryLogin(string username, string password)
        {
MySqlConnection con = new MySqlConnection("host=myhostname;user=myusername;password=mypassword;database=mydatabase;");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM test WHERE username = '" + username + "' AND password = '" + password + "';");
            cmd.Connection = con;
            con.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read() != false)
            {
                if (reader.IsDBNull(0) == true)
                {
                    cmd.Connection.Close();
                    reader.Dispose();
                    cmd.Dispose();
                    return false;
                }
                else
                {
                    cmd.Connection.Close();
                    reader.Dispose();
                    cmd.Dispose();
                    return true;

                }
            }
            else
            {
                return false;
            }
        }
    }
}
它显示以下错误:

“OverflowException未处理

算术运算导致溢出“


我这里没有使用任何算术运算。有什么帮助吗?

检查
mysql服务器中的
test

确保所有字段在
用户名
密码
列中都有有效值

更新

尝试在连接字符串中包含选项
“Use Pipe=false;”“
。然后它会很好地打开连接


我希望这对你有帮助

您可以发布堆栈跟踪或异常的其他详细信息吗?您将发现正在调用的某个库中发生异常。此外,您的代码当前暴露于主题外,您可能需要查看@philip kendall您的意思是:login.exe!login.Form1.tryLogin(字符串用户名,字符串密码)第39行C#这发生在哪一行?@Ajay你能把你的“堆栈跟踪”放在你的帖子上吗?@Ajay你可以放一个刹车点,然后在出现错误时获取堆栈跟踪。同时检查我上面的更新。当我添加时,使用Pipe=false;在连接字符串中,它表示“关键字不受支持”@Ajay您必须放置堆栈跟踪以获取更多帮助。有关获取堆栈跟踪,请参阅上面的注释。好的,谢谢您的帮助。问题在于Mysql connector/net 6.6.4版本。它放弃了对旧密码授权的支持。所以我必须卸载它并安装一个旧版本,最好是6.5.5