Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Fatal error encountered during command execution.


What I have tried:

<pre> mcmd.CommandText = "delete from results"
        mcmd.Connection = mycon
        mcmd.ExecuteNonQuery()
        mcmd.CommandText = "insert into results (MOB_NO, CNAME, BIRTH_DATE, F_H_NAME, L_HOUSE_NO, L_STREET, L_LOCALITY, L_CITY, L_STATE, L_PIN, ALTER_TELE_NO, CONN_TYPE, ACT_DATE) select MOB_NO, CNAME, BIRTH_DATE, F_H_NAME, L_HOUSE_NO, L_STREET, L_LOCALITY, L_CITY, L_STATE, L_PIN, ALTER_TELE_NO, CONN_TYPE, ACT_DATE from addressfull where " & crtext
        mcmd.Connection = mycon
        mdataadapter.SelectCommand = mcmd
        mdataadapter.Fill(myData)
        mcmd.ExecuteNonQuery()
        mcmd.CommandText = "select MOB_NO, TSP_NAME, CNAME, BIRTH_DATE, F_H_NAME, L_HOUSE_NO, L_STREET, L_LOCALITY, L_CITY, L_STATE, L_PIN, ALTER_TELE_NO, CONN_TYPE, ACT_DATE,ID_DOCMENT_NO from results"
        mcmd.Connection = mycon
        mdataadapter.SelectCommand = mcmd
        mdataadapter.Fill(myData)
        dgvmobilenos.DataSource = myData
Posted
Updated 14-Jul-23 19:54pm
Comments
Richard MacCutchan 15-Jul-23 3:39am    
You are trying to use an INSERT statement as the SelectCommand of a DataAdapter.
sudheerpolic 15-Jul-23 21:13pm    
MySql.Data.MySqlClient.MySqlException
HResult=0x80004005
Message=Fatal error encountered during command execution.
Source=MySql.Data
StackTrace:
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at MysqlConCode.frmmain.btntrack_Click(Object sender, EventArgs e) in D:\VB.NET TUTORIAL\Mobile Tracker 2022\MysqlConCode\Form1.vb:line 366
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at MysqlConCode.My.MyApplication.Main(String[] Args) in :line 83

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
MySqlException: Fatal error encountered attempting to read the resultset.

Inner Exception 2:
MySqlException: Reading from the stream has failed.

Inner Exception 3:
IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Inner Exception 4:
SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

after putting mdataadapter.InsertCommand = mcmd
Richard MacCutchan 16-Jul-23 2:59am    
Inner Exceptions 3 and 4 tell you what the problem is. You system cannot connect to the server, so that is what you need to investigate.
sudheerpolic 16-Jul-23 9:21am    
Respected Sir,

these action also worked successfully

If Len(Txtsrch.Text) < 10 And cbosearch.Text = "MOBILE NO" Or Len(Txtsrch.Text) < 10 And cbosearch.Text = "ALTERNATE NO" Then
MsgBox("Please enter a valid Mobile or Landphone Number")
Exit Sub
End If
Select Case cbosearch.Text
Case "MOBILE NO"
mcmd.CommandText = "select MOB_NO,TSP_NAME,CNAME,CONN_TYPE,BIRTH_DATE,F_H_NAME,L_HOUSE_NO,L_STREET,L_LOCALITY,L_CITY,L_STATE,L_PIN,ALTER_TELE_NO,EMAIL,ACT_DATE,P_HOUSE_NO,P_STREET,P_LOCALITY,P_CITY,P_STATE,ID_DOCMENT_NO,IMSI_NO,REF_NAME,REF_ADD,REF_TELE_NO from addressfull where MOB_NO=@0 order by act_date desc"
Case "ALTERNATE NO"
mcmd.CommandText = "select MOB_NO,TSP_NAME,CNAME,CONN_TYPE,BIRTH_DATE,F_H_NAME,L_HOUSE_NO,L_STREET,L_LOCALITY,L_CITY,L_STATE,L_PIN,ALTER_TELE_NO,EMAIL,ACT_DATE,P_HOUSE_NO,P_STREET,P_LOCALITY,P_CITY,P_STATE,ID_DOCMENT_NO,IMSI_NO,REF_NAME,REF_ADD,REF_TELE_NO from addressfull where ALTER_TELE_NO=@0 order by act_date desc"
Case "ID DOCUMENT NO"
mcmd.CommandText = "select MOB_NO,TSP_NAME,CNAME,CONN_TYPE,BIRTH_DATE,F_H_NAME,L_HOUSE_NO,L_STREET,L_LOCALITY,L_CITY,L_STATE,L_PIN,ALTER_TELE_NO,EMAIL,ACT_DATE,P_HOUSE_NO,P_STREET,P_LOCALITY,P_CITY,P_STATE,ID_DOCMENT_NO,IMSI_NO,REF_NAME,REF_ADD,REF_TELE_NO from addressfull where ID_DOCMENT_NO=@0 order by act_date desc"
Case "IMSI NO"
mcmd.CommandText = "select MOB_NO,TSP_NAME,CNAME,CONN_TYPE,BIRTH_DATE,F_H_NAME,L_HOUSE_NO,L_STREET,L_LOCALITY,L_CITY,L_STATE,L_PIN,ALTER_TELE_NO,EMAIL,ACT_DATE,P_HOUSE_NO,P_STREET,P_LOCALITY,P_CITY,P_STATE,ID_DOCMENT_NO,IMSI_NO,REF_NAME,REF_ADD,REF_TELE_NO from addressfull where IMSI_NO=@0 order by act_date desc"
End Select
mcmd.Connection = mycon
mcmd.Parameters.AddWithValue("@0", Trim(Txtsrch.Text))
mdatareader = mcmd.ExecuteReader()
If mdatareader.Read = False Then
MsgBox("SDR not found.......")
mcmd.Parameters.Clear()
mdatareader.Close()
Exit Sub
End If
If mdatareader.HasRows Then
printaddress()
While mdatareader.Read
printaddress()
End While
End If
'cmd.CommandTimeout = 99999
'da.SelectCommand = cmd
'da.Fill(myData)
'dgvmobilenos.DataSource = myData
mcmd.Parameters.Clear()
mdatareader.Close()
Richard MacCutchan 16-Jul-23 9:29am    
OK, but that does not actually prove anything. If you keep getting communication (i.e. socket/TCP/IP) errors then there is nothing anyone here can do to fix it.

1 solution

First off, don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

But there is where advice has to stop: we have no access to your database or the data you are handling - and no idea where in that code the error occurs.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900