0

VB.NET、MySQL を使用した Winforms アプリケーション。私のアプリでは、資金と接続の信頼性の制限のため、メールの添付ファイルを使用して更新する機能を追加しました。すべてがうまくいきます。Appsフォームのロードでも、ファイルの存在をチェックしています。存在する場合は、データベースに変更を加える必要があります。したがって、以下の Sub が呼び出され、そのファイルの内容が arrayList に読み込まれます... アプリが VS の外部から起動すると、「CommandText プロパティが正しく初期化されていません」というエラーが表示されます。

 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

問題がどこから来ているのかわからず、実行をずっと追跡しています... sList には、次のような有効な MYSQL コマンドが含まれています。

  ALTER TABLE `storage`.`property_info` ADD COLUMN `pfam_pName` CHAR(200) NULL  AFTER `pfam_Phone` ;

これで私を正しい方向に送ることができるアイデアはありますか???

4

1 に答える 1

1

empty stringコードにエラーは見つかりませんでしたが、スクリプトに空の行があり、コマンドテキストを渡すことができると思われます。これにファイルの読み取りを変更してください、

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

また

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
于 2012-10-07T23:56:06.423 に答える