Windows窗体“System.Data.dll中发生了'System.ArgumentException'类型的未处理异常”[复制]

问题描述 投票:-2回答:1

这个问题在这里已有答案:

我是C#语言,仍在学习模型视图控制。现在我有我的学校的项目来制作收银员应用程序,但是当我尝试连接mysql数据库时,我有这个错误。

错误是:

System.Data.dll中发生了未处理的“System.ArgumentException”类型异常

其他信息:不支持关键字:'port'。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace AppKasir.KoneksiDB
{
    class KoneksiBarang
    {
        public static SqlConnection getKoneksiBarang()
        {
            string strCon = "SERVER = localhost; PORT = 3306; UID = root; PWD = ; Database = db_kasirmysql;";
            return new SqlConnection(strCon);
        }
    }
}

错误在线:

return new SqlConnection(strCon);

其中符号;下划线为红色。

c# mysql winforms
1个回答
0
投票

System.Data.SqlClient.SqlConnection表示与SQL Server数据库的开放连接。

如果要访问MySQL数据库,请尝试此操作: How to connect to MySQL Database?

© www.soinside.com 2019 - 2024. All rights reserved.