简体   繁体   中英

Is there any way to hide the connection string on my MySQL Backup Restore code?

I have these code to backup and restore mysql from vb application.

These are my codes:

Dim DBFILE As String

        Try
            OpenFileDialog1.Filter = "SQL Dump File (*.sql)|*.sql|All files (*.*)|*.*"
            If OpenFileDialog1.ShowDialog = DialogResult.OK Then
                DBFILE = OpenFileDialog1.FileName
                Dim BackupProcess As New Process
                BackupProcess.StartInfo.FileName = "cmd.exe"
                BackupProcess.StartInfo.UseShellExecute = False
                BackupProcess.StartInfo.WorkingDirectory = "C:\xampp\mysql\bin\"
                BackupProcess.StartInfo.RedirectStandardInput = True
                BackupProcess.StartInfo.RedirectStandardOutput = True
                BackupProcess.Start()

                Dim BackupStream As StreamWriter = BackupProcess.StandardInput
                Dim myStreamReader As StreamReader = BackupProcess.StandardOutput
                BackupStream.WriteLine("mysql --user=" & dbUser & " --password=" & dbPassword & " -h " & dbServer & " " & dbName & " < """ + DBFILE + """")

                BackupStream.Close()
                BackupProcess.WaitForExit()
                BackupProcess.Close()
                MsgBox("Restore succesfully", vbOKOnly + vbInformation, "Restore info")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

When i executed these codes in my application, a command prompt window opened like this: Command Prompt shown when Backup and Restore

At the title bar, it clearly shown my connection string.

  1. The user
  2. The password
  3. The server name
  4. The database name

How do i hide this string or any idea to not show this command prompt window?

Thanks in advance for give some attention and helping me.

Set another option:

BackupProcess.StartInfo.CreateNoWindow = True

Alternatively, can you specify the conn str as a command line argument for a different result?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM