Reputation: 1559
VB.NET, Winforms Application with MySQL. In my app I have added the ability to Update it through the use of mail attachments because of limitations of Funds and Connection reliability. Everything works good. Well in the Apps form load even I have it check for the existence of a file. If it exists there are changes to be made to the database. So the below Sub is called and the contents of that file are read in to an arrayList... I am getting the "CommandText property has not been properly Initialized" error when the app starts from outside VS.
Private Sub sqlUpdate(ByVal sqlScriptName As String)
Dim D As Boolean = BackupDatabase("C:\xxxxxxxx\temp.sql")
Dim objReader As New StreamReader(sqlScriptName)
Dim sLine As String = ""
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
arrText.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
For Each sLine In arrText
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim connString As String = My.Settings.storageConnectionString
conn.ConnectionString = connString
myCommand.Connection = conn
myCommand.CommandText = String.Empty
Try
myCommand.CommandText = sLine
conn.Open()
myCommand.ExecuteNonQuery()
Catch myerror As MySqlException
'MsgBox("There was an error updating the database: " & myerror.Message + vbNewLine + "PLEASE CONTACT THE DEVELOPER IMMEDIATELY")
End Try
Next
Return
End Sub
Not sure where the Problem is comming from and have followed the execution all the way down... The sList contains Valid MYSQL commands that look like this:
ALTER TABLE `storage`.`property_info` ADD COLUMN `pfam_pName` CHAR(200) NULL AFTER `pfam_Phone` ;
Any ideas that could send me in the right direction with this???
Upvotes: 0
Views: 3003
Reputation: 263723
I found no error on your code but I suspect that there are empty lines in your script thus allowing it to pass empty string
on your command text. Please do modify the reading of file into this,
Do
sLine = objReader.ReadLine()
If (Not sLine Is Nothing) Then
If sLine.Trim().Length <> 0 Then ' this will not add empty line '
arrText.Add(sLine)
End If
End If
Loop Until sLine Is Nothing
or
For Each sLine In arrText
If sLine.Trim().Length = 0 Then Continue For ' skips for empty line '
Try
myCommand.CommandText = sLine
myCommand.ExecuteNonQuery()
Catch myerror As MySqlException
MsgBox("There was an error updating the database: " & _
myerror.Message & vbNewLine & _
"PLEASE CONTACT THE DEVELOPER IMMEDIATELY")
End Try
Next
Upvotes: 1