연결 시도 시 Windows의 MySQL이 충돌함 (MySQL on Windows crashes on connection attempts)


문제 설명

연결 시도 시 Windows의 MySQL이 충돌함 (MySQL on Windows crashes on connection attempts)

I have a windows application that I am making for a friend, but for some reason, when I try to connect, the app crashes. a message box pops up and says "DBTest hastopped working, windows is checking for a solution to the problem..." after 5 seconds, it closes and the app doesn't launch.

However, when I comment out the info from the app, it works again, but only the app launches, and I can't connect anymore??

I checked the connection on MySQL workbench, and it lets me connect to the website's database, and I can connect to the sites DB remotely, but it will not allow me to do so in the application.

Heres the code that im testing, and the app keeps crashing.

I'm at a loss.

    public partial class Form1 : Form
{
    public MySqlConnection connection;
    public Form1()
    {

        InitializeComponent();

        DBInfo db = new DBInfo();

        string server;
        string database;
        string uid;
        string password;

        server = "XXX";
        database = "XXX";
        uid = "XXX";
        password = "XXX";
        string connectionString;
        connectionString = "Server=" + server + ";" + "Database=" + database + ";"
                + "Uid=" + uid + ";" + "Password" + password + ";";

        connection = new MySqlConnection(connectionString);

        try
        {
            connection.Open();
        }
        catch (MySqlException ex)
        {
            switch (ex.Number)
            {
                case 0:
                    MessageBox.Show("Cannot connect to Server. Contact Admin.");
                    break;

                case 1045:
                    MessageBox.Show("Invalid Username/Password, please try again.");
                    break;
            }
        }
    }

UPDATE:

System.ArgumentException: Format of the initialization string does not conform to specification starting at index 54. at System.Data.Common.DBConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstkey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean use OdbcRules) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(string connStr) at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString) at DBtest.Form1..ctor() in C:\Users\AlexMoreno\Dcouments\Visual Studio\2008\Projects\DBtest\Form1.cs:line 38


참조 솔루션

방법 1:

Wrap a try/catch around the statement to open the connection, and get the details of the exception that is likely being thrown and unhandled:

public partial class Form1 : Form
{
    public MySqlConnection connection;
    public Form1()
    {

        InitializeComponent();

        //DBInfo db = new DBInfo(); // would comment this out since you're not using it

        string server;
        string database;
        string uid;
        string password;

        server = "XXX";
        database = "XXX";
        uid = "XXX";
        password = "XXX";
        string connectionString;
        connectionString = "Server=" + server + ";" + "Database=" + database + ";"
                + "Uid=" + uid + ";" + "Password" + password + ";";

        //connection = new MySqlConnection(connectionString); // not here ‑ for troubleshooting at least

        try
        {
            connection = new MySqlConnection(connectionString); // relocated from above for troubleshooting
            connection.Open();
        }
        (Exception ex) // Yes, Exception ‑ until you know more about what is happening.
        {
            MessageBox.Show(ex.ToString());
        }
    }
}

You could output the details of the error another way ‑ e.g. log them, output them to Debug.Console if you are going to debug the app in Visual Studio; take your pick; you just need to reality check that an exception is unhandled and get its details to proceed.

Also, try commenting out DBInfo db = new DBInfo();.  You don't seem to be using it anyway.

UPDATE:

You are missing an = in your connection string ‑ right after Password.  So...

connectionString = "Server=" + server + ";" + "Database=" + database + ";"
            + "Uid=" + uid + ";" + "Password" + password + ";";

...should be:

connectionString = "Server=" + server + ";" + "Database=" + database + ";"
            + "Uid=" + uid + ";" + "Password=" + password + ";";

(by Alex MorenoJ0e3gan)

참조 문서

  1. MySQL on Windows crashes on connection attempts (CC BY‑SA 3.0/4.0)

#crash #MySQL #debugging #C# #Database






관련 질문

WebView가 전체 활동을 죽이고 있습니다 --- 이것을 어떻게 디버깅 할 수 있습니까? (WebView killing the whole activity --- How can I debug this?)

연결 시도 시 Windows의 MySQL이 충돌함 (MySQL on Windows crashes on connection attempts)

휘발성 멤버는 멤버 함수에서 액세스할 수 없습니다. (volatile member can not be accessed by member function)

Ruby에서 Gosu로 텍스트를 인쇄할 수 없음(충돌) (Cannot print a text with Gosu in Ruby (crash))

이 기능은 .exe를 충돌시킵니다. 제가 뭘 잘못하고 있습니까? (This function makes the .exe crash, what am I doing wrong?)

PyAudio로 웨이브를 재생하는 Tkinter 버튼 호출 기능 - 충돌 (Tkinter button calling function to play wave with PyAudio -- crashes)

phonegap 카메라가 앱 충돌 (phonegap camera crashes the app)

대화 상자를 표시하려고 할 때 앱이 충돌함 (App crashed when try to display dialog box)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

WordPress에서 Simple Jquery Click이 작동하지 않음 (Simple Jquery Click not working in WordPress)

새 줄이 발견되지 않으면 fget이 NULL을 반환하지 않습니다. (fgets dont return NULL when no new line found)

webview가 검은 색으로 바뀌고 응용 프로그램이 충돌합니다. (webview turns black and application crashes)







코멘트