Heim  >  Fragen und Antworten  >  Hauptteil

C#-MySQL-Verbindungsproblem: Es kann keine Verbindung zum angegebenen MySQL-Host hergestellt werden

<p>Als ich den folgenden Code ausgeführt habe, ist der obige Fehler aufgetreten -</p> <pre class="brush:php;toolbar:false;">MySqlConnection mysqlConn=new MySqlConnection("server=127.0.0.1;uid=pankaj;port=3306;pwd=master;database=patholabs;"); mysqlConn.Open();</pre> <p>Ich habe versucht, den Server auf „localhost“ und den Benutzer auf „root“ zu setzen, aber ich habe die folgende Fehlermeldung erhalten: </p> <pre class="brush:php;toolbar:false;">Fehler: 0: Es konnte keine Verbindung zu einem der angegebenen MySQL-Hosts hergestellt werden. System.Transactions Critical: 0: <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft. com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled Exception</Description><AppDomain>DBSync.exe</AppDomain><Exception>< ;ExceptionType> MySql.Data.MySqlClient.MySqlException, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d</ExceptionType><Message>Es konnte keine Verbindung zu einem der angegebenen MySQL-Hosts hergestellt werden.</Message><StackTrace> bei MySql.Data.MySqlClient.NativeDriver.Open() bei MySql.Data.MySqlClient.Driver.Open() bei MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder-Einstellungen) bei MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() bei MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() bei MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() bei MySql.Data.MySqlClient.MySqlPool.GetConnection() bei MySql.Data.MySqlClient.MySqlConnection.Open() bei DBSync.MainForm.BtnCalculateClick(Object sender, EventArgs e) in c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncMainForm.cs:line 51 bei System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&amp;amp; m) bei System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m) at System.Windows.Forms.Button.WndProc(Message&amp;amp; m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg) bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32-Grund, ApplicationContext-Kontext) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32-Grund, ApplicationContext-Kontext) bei System.Windows.Forms.Application.Run(Form mainForm) bei DBSync.Program.Main(String[] args) in c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncProgram.cs:line 27</StackTrace><ExceptionString>MySql.Data.MySqlClient.MySqlException (0x80004005): 无法连接到指定的任何MySQL-Version.bei MySql.Data.MySqlClient.NativeDriver.Open() bei MySql.Data.MySqlClient.Driver.Open() bei MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder-Einstellungen) bei MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() bei MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() bei MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() bei MySql.Data.MySqlClient.MySqlPool.GetConnection() bei MySql.Data.MySqlClient.MySqlConnection.Open() bei DBSync.MainForm.BtnCalculateClick(Object sender, EventArgs e) in c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncMainForm.cs:line 51 bei System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&amp;amp; m) bei System.Windows.Forms.ButtonBase.WndProc(Message&amp;amp; m) at System.Windows.Forms.Button.WndProc(Message&amp;amp; m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg) bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32-Grund, ApplicationContext-Kontext) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32-Grund, ApplicationContext-Kontext) bei System.Windows.Forms.Application.Run(Form mainForm) bei DBSync.Program.Main(String[] args) in c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncProgram.cs:line 27</ExceptionString><DataItems><Data><Key>Server Error Code</Key>< Value>1042</Value></Data></DataItems></Exception></TraceRecord></pre> <p> 编辑:我注意到当我使用sharpdevelop时出现错误, 而在使用Visual Studio时没有出现错误.</p>
P粉994092873P粉994092873426 Tage vor480

Antworte allen(1)Ich werde antworten

  • P粉078945182

    P粉0789451822023-08-21 15:06:06

    有时候连接字符串中的间距和参数的顺序是有关系的(根据个人经验和一个漫长的夜晚 :S)

    所以要坚持使用标准格式,请参考这里

    Antwort
    0
  • StornierenAntwort