我有这些代码可以从vb应用程序备份和还原mysql。
这些是我的代码:
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
当我在应用程序中执行这些代码时,将打开一个命令提示符窗口,如下所示: Command Prompt shown when Backup and Restore
在标题栏中,它清楚地显示了我的连接字符串。
- 用户
- 密码
- 服务器名称
- 数据库名称
如何隐藏此字符串或任何不显示此命令提示符的想法 窗口?
在此先感谢您的关注和帮助。
答案 0 :(得分:0)
设置另一个选项:
BackupProcess.StartInfo.CreateNoWindow = True
或者,您可以将conn str指定为不同结果的命令行参数吗?