为什么My C #Windows表单应用程序没有连接到mysql服务器?

时间:2015-11-11 13:49:47

标签: c# mysql windows

我正准备制作一个程序,你可以从mysql数据库中搜索东西,但它没有连接到我的mysql服务器(我正在使用C#Windows表单应用程序,Microsoft visual studio 2012) 这是连接字符串:

public String ConnectionString = "Server=*******;Database=*********;Uid=********;Pwd=*******";

继承我连接并获取数据的代码:

        MySqlConnection con;
    MySqlCommand cmd;
    private void searchbtn_Click(object sender, EventArgs e)
    {
        if (search.Text == "" || search.Text == "Search games or programs")
        {
            return;
        }
        else
        {

            try
            {
            con = new MySqlConnection(ConnectionString);
            progress.Value = 10;
            con.Open();
            progress.Value = 20;
                s.Clear();
                cmd = con.CreateCommand();
                progress.Value = 30;
                cmd.CommandText = "SELECT * FROM games WHERE game='" + search.Text + "'";
                MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adap.Fill(ds);
                DataTable dtable = ds.Tables["game"];
                for (int i = 0; i <= dtable.Rows.Count - 1; i++)
                {
                    s.Items[i].SubItems.Add(dtable.Rows[i].ItemArray[1].ToString());
                }
                if (s == null)
                {
                    s.Items[0].SubItems.Add("No games found!");
                }
            }
            catch (Exception)
            {
                errors.Text = "[ERROR] Could not connect to server!";
                progress.ForeColor = Color.Red;
                return;
            }
            finally
            {
                con.Close();

            }
        }
    }



}

错误只是我无法连接到服务器我做错了什么? 感谢。

错误消息:

&#13;
&#13;
<textarea>"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C: \ Windows \ Microsoft.Net \ assembly \ GAC_32 \ mscorlib \ v4.0_4.0.0.0__b77a5c561934e089 \ mscorlib.dll" loaded, loading symbols is skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C: \ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System \ v4.0_4.0.0.0__b77a5c561934e089 \ System.dll" loaded, loading symbols is skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C: \ Users \ Frank \ Documents \ Visual Studio 2012\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\MySql.Data\v4.0_6.9.8.0__c5687fc88969c44d\MySql.Data.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C: \ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ MySql.Web \ v4.0_6.9.8.0__c5687fc88969c44d \ MySql.Web.dll" loaded , the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.</textarea>
The thread 'vshost.NotifyLoad' (0x1624) has ended with code 0 (0x0).
The thread 'vshost.LoadReference' (0x1750) has ended with code 0 (0x0).
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C: \ Users \ Frank \ Documents \ Visual Studio 2012\Projects\WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe" loaded, loaded symbols.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
"WindowsFormsApplication2.vshost.exe" (Managed (v4.0.30319)): "C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll" loaded, the loading of icons was skipped. The module is optimized, and the debug option 'Just My Code' is enabled.
WindowsFormsApplication2.vshost.exe Error: 0: Unable to connect to any of the specified MySQL hosts.
An exception (first chance) of the type "MySql.Data.MySqlClient.MySqlException" has occurred in MySql.Data.dll.
The thread 'vshost.RunParkingWindow' (0xd0c) has ended with code 0 (0x0).
The thread '<No Name>' (0x10b4) has ended with code 0 (0x0).
The program '[1752] WindowsFormsApplication2.vshost.exe: Maintained (v4.0.30319) "was exited with code 0 (0x0).
&#13;
&#13;
&#13;

它是从德语翻译成英语的,因为我的程序是geman但它不能改变语言

0 个答案:

没有答案