我正在尝试在 C++ Windows 窗体和 mysql 数据库之间建立连接, 但它向我显示了这个错误。
a handle to a non-managed class is not allowed
#pragma endregion
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
std::string^ constring =L "datasource=localhost;port=**;username=root;password=**";
MySqlConnection^ conDataBase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase=gcnew MySqlCommand("",conDataBase);
}
};
}
最佳答案
std::string
是 C++ 标准库中的字符串类。您不能将它与 ^
一起使用(即,作为托管类)。
改为使用 .NET String 类:
System::String^ constring = L"datasource=localhost;port=**;username=root;password=**";
关于c++ - 不允许使用非托管类的句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49215845/