0

アプリケーション (Windows x64 ベース) で mysql++ ライブラリを使用しようとしましたが、SQL サーバーに接続できないようです。いくつかの情報:

このコードを使用してサーバーに接続しました。

mysqlpp::Connection conn(db, 0, user, pass, 3306);

これには間違いなく正しいデータが含まれています。

そして、私のSQLサーバーはMySQLインストールの標準サービスです。そして、私は標準設定を使用したと確信しています。MySql Workbench を使用して接続でき、いくつかの新しいテーブルなどを編集しましたが、自分のプログラムが接続していないようです。

ドキュメントを読みましたが、接続できない理由を示唆する特定の情報が見つかりません。

4

1 に答える 1

1

ああ、非常に多くの問題があり、時間がほとんどありません...

プログラムにデータベースへのアクセス権限があることを確認しましたか?

あなたのプログラムは正しい特権を持っていますか?

ホスト名は正しいですか?

どのようなエラーが発生していますか?

どの例外がスローされますか?

デバッガーを使用すると、エラーは何行目に発生しますか?

これが私の方法です:

sql::Connection * const
Manager ::
get_db_connection(void) const
{
    //-------------------------------------------------------------------------
    //  Use only one connection until proven that more connections will make
    //      the program more efficient or have a beneficial impact on the user.
    //  Thus the change in returning sql::Connection * rather than a smart pointer.
    //      A smart pointer will delete its contents.
    //-------------------------------------------------------------------------
    static const char                   host_text[] = "tcp://127.0.0.1:3306/";
    static std::string                  host_name;
    if (!m_connection_initialized)
    {
        host_name = host_text;
        initialize_db_driver();
        host_name += m_dataset_info.m_dsn_name;
        try
        {
            m_p_connection = m_p_sql_driver->connect(host_name.c_str(),
                                                   m_dataset_info.m_user_name.c_str(),
                                                   m_dataset_info.m_password.c_str());
        }
        catch (sql::SQLException &e)
        {
            /*
            The MySQL Connector/C++ throws three different exceptions:

            - sql::MethodNotImplementedException (derived from sql::SQLException)
            - sql::InvalidArgumentException (derived from sql::SQLException)
            - sql::SQLException (derived from std::runtime_error)
            */
            wxString    wx_text = wxT("# ERR: SQLException in ");
            wx_text += wxT(__FILE__);
            wxLogDebug(wx_text);
            wx_text.Printf(wxT("# ERR: (%s) on line %d"),
                           __FUNCTION__,
                           __LINE__);
            wxLogDebug(wx_text);
            wx_text.Printf(wxT("# ERR: %s (MySQL error code: %d, SQLState: %s)"),
                e.what(),
                e.getErrorCode(),
                e.getSQLState());
            wxLogDebug(wx_text);
            wxLogDebug(wxT("Verify that mysqlcppconn.dll is in the PATH or in the working directory."));
            //      throw Manager_Connection_Not_Initialized();
            m_connection_initialized = false;
        }
        catch (...)
        {
            std::cout << "Unhandled database SQL exception\n" << flush;
            m_connection_initialized = false;
        }           
        m_connection_initialized = true;
    }
    return m_p_connection;
}
于 2013-12-29T03:03:08.057 に答える