Isu sambungan C# MySQL: Tidak dapat menyambung ke hos MySQL yang ditentukan
P粉994092873
2023-08-20 19:50:26
<p>Apabila saya melaksanakan kod berikut, saya mengalami ralat di atas -</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>Saya cuba menetapkan pelayan kepada localhost dan pengguna kepada root, tetapi saya mendapat ralat berikut -</p>
<pre class="brush:php;toolbar:false;">Ralat: 0: Tidak dapat menyambung ke mana-mana hos MySQL yang ditentukan.
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</AppDomain>Exception> MySql.Data.MySqlClient.MySqlException, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d</ExceptionType><Message>Tidak dapat menyambung ke mana-mana MySQL yang ditentukan.</Message><StackTrace>
di MySql.Data.MySqlClient.NativeDriver.Open()
di MySql.Data.MySqlClient.Driver.Open()
di MySql.Data.MySqlClient.Driver.Create(Tetapan MySqlConnectionStringBuilder)
di MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
di MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
di MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
di MySql.Data.MySqlClient.MySqlPool.GetConnection()
di MySql.Data.MySqlClient.MySqlConnection.Open()
di DBSync.MainForm.BtnCalculateClick(Penghantar objek, EventArgs e) dalam c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncMainForm.cs:line 51
di System.Windows.Forms.Control.OnClick(EventArgs e)
di System.Windows.Forms.Button.OnClick(EventArgs e)
di System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
di System.Windows.Forms.Control.WmMouseUp(Message&amp; m, butang MouseButtons, klik Int32)
di System.Windows.Forms.Control.WndProc(Message&amp; m)
di System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
di System.Windows.Forms.Button.WndProc(Message&amp; m)
di System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
di System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
di System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
di System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
di System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
di System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(sebab Int32, konteks ApplicationContext)
di System.Windows.Forms.Application.ThreadContext.RunMessageLoop(sebab Int32, konteks ApplicationContext)
di System.Windows.Forms.Application.Run(Form mainForm)
di DBSync.Program.Main(String[] args) dalam c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncProgram.cs:line 27</StackTrace><ExceptionString>MySql.Data.MySql0Exception.MySql0Exception接到指定的任何MySQL主机。di MySql.Data.MySqlClient.NativeDriver.Open()
di MySql.Data.MySqlClient.Driver.Open()
di MySql.Data.MySqlClient.Driver.Create(Tetapan MySqlConnectionStringBuilder)
di MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
di MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
di MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
di MySql.Data.MySqlClient.MySqlPool.GetConnection()
di MySql.Data.MySqlClient.MySqlConnection.Open()
di DBSync.MainForm.BtnCalculateClick(Penghantar objek, EventArgs e) dalam c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncMainForm.cs:line 51
di System.Windows.Forms.Control.OnClick(EventArgs e)
di System.Windows.Forms.Button.OnClick(EventArgs e)
di System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
di System.Windows.Forms.Control.WmMouseUp(Message&amp; m, butang MouseButtons, klik Int32)
di System.Windows.Forms.Control.WndProc(Message&amp; m)
di System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
di System.Windows.Forms.Button.WndProc(Message&amp; m)
di System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
di System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
di System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
di System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
di System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
di System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(sebab Int32, konteks ApplicationContext)
di System.Windows.Forms.Application.ThreadContext.RunMessageLoop(sebab Int32, konteks ApplicationContext)
di System.Windows.Forms.Application.Run(Form mainForm)
di DBSync.Program.Main(String[] args) dalam c:Documents and SettingsTest01My DocumentsSharpDevelop ProjectsDBSyncDBSyncProgram.cs:line 27</ExceptionString><DataItems><Data><SharpDevelop ProjectsDBSyncDBSyncProgram.cs:line 27</ExceptionString><DataItems><Data><Data><Server><Server> Nilai>1042</Nilai></Data></DataItems></Exception></TraceRecord></pre>
<p>我可以通过mysql workbench连接到mysql服务器并查询数据库。只有代码不起作用。
编辑:我注意到当我使用sharpdevelop时出现错误,而在使用Visual Studio时没有出现错误。</p>
Kadangkala jarak dalam rentetan sambungan berkaitan dengan susunan parameter (berdasarkan pengalaman peribadi dan malam yang panjang :S)
Jadi untuk berpegang pada format standard, sila rujuk di sini