0

我正在尝试连接到 mySql DB。这个数据库应该支持希伯来语。在我的连接字符串中,我添加了关键字:charSet = UTF8。尝试打开连接时出现以下异常:不支持关键字:'charset'。异常发生在这一行:[ myDataCon = new DataContext(GetConnectionString());]

我的代码:

[ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data.Linq;
using System.Collections;

namespace ConstructionProjectBackgroundService
{
    class DBHandler
    {
        static DBHandler dbHandler;
        DataContext myDataCon;
        public MySqlConnection DataConnection { get; set; }
        public DataContext Dc
        {
            get { return myDataCon; }
        }

        private string GetConnectionString()
        {

            string connString = "User = root; Server = localhost; Database = construction_project; charset = UTF8;";        //connString for MySQLPHPAdmin
            return connString;
        }

        private DBHandler()
        {
            DataConnection = new MySqlConnection(GetConnectionString());
            myDataCon = new DataContext(GetConnectionString());
        }

        public static DBHandler GetInstance()
        {
            if (dbHandler == null)
            {
                dbHandler = new DBHandler();
            }
            return dbHandler;
        }

        public ArrayList execQuery(string query)
        {

            MySqlCommand command = DBHandler.GetInstance().DataConnection.CreateCommand();

            try
            {
                DBHandler.GetInstance().DataConnection.Open();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            command.CommandText = query;
            MySqlDataReader reader = command.ExecuteReader();

            ArrayList Filters = new ArrayList();

            while (reader.Read())
            {
                string[] temp = new string[reader.FieldCount + 1];
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    temp[i] = reader[i].ToString();
                }
                Filters.Add(temp);
            }
            DBHandler.GetInstance().DataConnection.Close();

            return Filters;
        }
    }
}
]

谢谢!!

4

0 回答 0