vb.net, Restore mysql database not working in windows xp - mysql

I have a code in restoring mysql database using vb.net. It perfectly works in windows 7 but when I try it in windows xp it's not working. Hope you can all help me with this. here's my code..
Function RestoreDb()
With dlg_openfile 'Executes a series of statements making repeated reference to a single object or structure.
.Title = "Please Select a Image" 'title
.InitialDirectory = "C:\" 'browse start directory
.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" 'only possible to select this extensions
.FilterIndex = 0 'index number filter
.FileName = "" 'empty
Dim answ = .ShowDialog
If answ = DialogResult.OK Then 'if answer not cancel, etc..
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = "C:\wamp\bin\mysql\mysql5.5.24\bin\"
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine(String.Format("mysql -u IS_DB -p2240624 db_innovaserver < {0}", .FileName))
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
End If
End With
End Function

Try this
Function RestoreDb()
With dlg_openfile 'Executes a series of statements making repeated reference to a single object or structure.
.Title = "Please Select a Image" 'title
.InitialDirectory = "C:\" 'browse start directory
.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" 'only possible to select this extensions
.FilterIndex = 0 'index number filter
.FileName = "" 'empty
Dim answ = .ShowDialog
If answ = DialogResult.OK Then 'if answer not cancel, etc..
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine(String.Format("C:\wamp\bin\mysql\mysql5.5.24\bin\mysql.exe -u IS_DB -p2240624 db_innovaserver < {0}", "dbFile.sql"))
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
End If
End With
End Function

Related

Why is Google Drive returning 'Failed to parse Content-Range header.'?

Here's my simple-dimple code for resuming a (possibly) interrupted upload to Google Drive:
Using message = New ByteArrayContent(New Byte() {})
message.Headers.ContentRange = New Headers.ContentRangeHeaderValue(Session.Size)
'message.Headers.TryAddWithoutValidation("Content-Range", "bytes */*")
Dim response = Await PutAsync("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=" & Session.Code, message)
Dim msg = Await response.Content.ReadAsStringAsync
'ERR: this is always 'Failed to parse Content-Range header.'
Dim position = 0L
If response.Headers.Contains("Range") Then
Dim range = response.Headers.GetValues("Range")
position = range.First.SplitPlus("-")(1)
End If
but Google keeps on returning
Failed to parse Content-Range header.
I checked the header manually, and it seems ok:
Content-Range: bytes */389587456
Content-Length: 0
What may the matter be?
What I tried:
Using StringContent instead of ByteArrayContent
Using TryAddWithoutValidation with */*
Neither work
With appeciation,
UPDATE
I tried uploading a new file from scratch. Fresh upload. Here's the code:
If response.StatusCode = 308 Then
Using fileStream = New ThrottledFileStream(Session.FilePath)
fileStream.Position = position
Using Content = New StreamContent(fileStream)
Content.Headers.ContentRange = New Headers.ContentRangeHeaderValue(position, Session.Size, Session.Size)
Using Timer = New Timer(Sub(o)
Dim ps As Long
If fileStream.CanRead Then ps = fileStream.Position
Progress.Invoke(New CloudUploadState With {.Response = response, .Position = ps})
End Sub, Nothing, 0, 20000)
Dim finishResponse = Await Put("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=" & Session.Code, Content)
Progress.Invoke(New CloudUploadState With {.Response = finishResponse})
End Using
End Using
End Using
End If
But i get the exact same response:Failed to parse Content-Range header.
This is after the entire file was uploaded (based on the time it takes to return, and the position of the filesteam)
Whats wrong with my request?
Thanks
For completeness, here's the entire code basically. I'd appreciate any help or pointers:
Public Async Function Upload(Session As DriveSession, Progress As Action(Of CloudUploadState)) As Task Implements ICloudStorage.Upload
Await EnsureCredentials()
If Session.Code Is Nothing Then
Dim path = Session.FilePath
If Debugger.IsAttached Then path = IO.Path.Combine("Test", path.Replace("\\", "\").Replace(":", ""))
Dim currentFolderId = ""
For Each nextFolderName In path.Split("\")
Dim url = $"https://www.googleapis.com/drive/v3/files?fields=files(name,id)&q=name='{nextFolderName}'"
If currentFolderId <> "" Then url &= $" and '{currentFolderId}' in parents"
If path.EndsWith("\" & nextFolderName) Then
Dim metadata = New JObject From {{"name", IO.Path.GetFileName(path)}}
metadata("parents") = New JArray From {currentFolderId}
Using message = New StringContent(metadata.ToString, Encoding.UTF8, "application/json")
message.Headers.Add("X-Upload-Content-Type", GetExtMime(IO.Path.GetExtension(path).LeftCut(".")))
message.Headers.Add("X-Upload-Content-Length", Session.Size)
Dim response = Await Post($"https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable", message)
Session.Code = response.Headers.Location.QueryParams("upload_id")
Using d = GetSystemContext(True)
Dim ds = d.Find(Of DriveSession)(Session.ID)
ds.Code = Session.Code
d.SaveChanges()
End Using
End Using
'End If
Else
url &= " and mimeType = 'application/vnd.google-apps.folder'"
Dim ret = Await GetString(url)
Dim files = ParseResponse(ret)
If files.Count > 1 Then DevError("identical names")
If files.Any Then
currentFolderId = files.First.Id
Else
Dim data = New JObject From {{"name", nextFolderName}, {"mimeType", "application/vnd.google-apps.folder"}}
If currentFolderId IsNot Nothing Then data.Add(New JProperty("parents", New JArray(currentFolderId)))
Using content = New StringContent(data.ToString, Encoding.UTF8, "application/json")
Using response = Await Post("https://www.googleapis.com/drive/v3/files", content)
Dim message = Await response.Content.ReadAsStringAsync
currentFolderId = JObject.Parse(message).Value(Of String)("id")
End Using
End Using
End If
End If
Next
End If
Using message = New ByteArrayContent(New Byte() {})
message.Headers.ContentRange = New Headers.ContentRangeHeaderValue(Session.Size)
Dim response = Await PutAsync("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=" & Session.Code, message)
Dim position = 0L
If response.Headers.Contains("Range") Then
Dim range = response.Headers.GetValues("Range")
position = range.First.SplitPlus("-")(1)
End If
Progress.Invoke(New CloudUploadState With {.Response = response, .Position = position})
If response.StatusCode = 308 Then
Using fileStream = New ThrottledFileStream(Session.FilePath)
fileStream.Position = position
Using Content = New StreamContent(fileStream)
Content.Headers.ContentRange = New Headers.ContentRangeHeaderValue(position, Session.Size, Session.Size)
Using Timer = New Timer(Sub(o)
Dim ps As Long
If fileStream.CanRead Then ps = fileStream.Position
Progress.Invoke(New CloudUploadState With {.Response = response, .Position = ps})
End Sub, Nothing, 0, 30000)
Dim finishResponse = Await PutAsync("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=" & Session.Code, Content)
Progress.Invoke(New CloudUploadState With {.Response = finishResponse})
End Using
End Using
End Using
End If
End Using
End Function
Ok. got it. was missing in the request "content-Length:0"
I made the same mistake, but I fixed it by changing to:
"Content-Range: bytes 0-*/*"

Creating a "Workbook.Connections("MyDBx").ODBCConnection" from a UserDSN or an ODBC file

Excel 2016 on a Windows 10 Pro computer: I can open a workbook and from the
DATA / From Other Sources / Data Connection Wizard / odbc DSN
where I select my User DSN and supply additional info.
It then creates the VBA code to set up a connection between my computer and an external SQL data base. I have previously defined a UserDSN for this connection.
If I record this process I end up with something like this:
With ActiveWorkbook.Connections("MyDBx").ODBCConnection
.BackgroundQuery = True
.CommandType = xlCmdSql
.Connection = "ODBC;DSN=SQL2;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = "D:\MyDocs\My Data Sources\Mydbx.odc"
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DSN=SQL2;" _
, Destination:=Range("$A$1")).QueryTable
.CommandText = Array("SELECT * FROM `MyDBx`.`tablea`")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = "D:\MyDocs\My Data Sources\MyDBx.odc"
.Refresh BackgroundQuery:=False
End With
This works and I can follow it with the VBA code to analyze and plot the data.
However, if I delete the sheet created above and then try to rerun the macro, it will fail on the statement
With ActiveWorkbook.Connections("MyDBx").ODBCConnection
There is also a warning when I delete the above sheet, that the sheet to be deleted contains a query.
How to capture/create the code in a macro which will allow my macro to run in a new/blank workbook using the above data connection.
Obviously I can keep the sheet and always run the macro in that workbook, but not in another workbook.
Please try to build it object by object like this:
Private Sub NewWorkbookWithODBCConnection()
Dim myWorkBook As Workbook
Dim myWorkbookConnection As WorkbookConnection
Dim myWorksheet As Worksheet
Dim myQuerytable As QueryTable
Set myWorkBook = Workbooks.Add
Set myWorkbookConnection = myWorkBook.Connections.Add2( _
Name:="MyDBx", _
Description:="Whatever", _
ConnectionString:="ODBC;DSN=SQL2;", _
CommandText:="")
With myWorkbookConnection.ODBCConnection
.BackgroundQuery = True
.CommandType = xlCmdSql
.Connection = "ODBC;DSN=SQL2;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = "D:\MyDocs\My Data Sources\Mydbx.odc"
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
Set myWorksheet = myWorkBook.Worksheets.Add
Set myQuerytable = myWorksheet.ListObjects.Add( _
SourceType:=0, _
Source:="ODBC;DSN=SQL2;", _
Destination:=Range("$A$1")).QueryTable
With myQuerytable
.CommandText = Array("SELECT * FROM `MyDBx`.`tablea`")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = "D:\MyDocs\My Data Sources\MyDBx.odc"
.Refresh BackgroundQuery:=False
End With
End Sub

Error in VB.NET mysqldump export with two conditions

I have a problem exporting my desired output. I want to use 'AND' in the where clause but it's not working. But when I use only one of the condition ex. --where=clientid='" + clientid + "', it's working. But when I add status='', its not working anymore. What is my error here? Thanks!
Code:
Sub Export()
Dim file As String
Dim clientid = frmDashboard.txtClientID.Text
SaveFileDialog1.Filter = "SQL Dump File (*.sql)|*.sql|All files (*.*)|*.*"
SaveFileDialog1.FileName = "CUST" + clientid + ".sql"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
file = SaveFileDialog1.FileName
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = "C:\Program Files\MySQL\MySQL Server 5.7\bin"
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
Dim status = ""
myStreamWriter.WriteLine("mysqldump -u administrator --password=password --skip-add-drop-table --no-create-info -h localhost cashloan clientcustomers --where=clientid='" + clientid + "' and status=''> " + file + " ") 'clientcustomers --where=clientid=" + clientid + "
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
MsgBox("Export was finished successfully.", MsgBoxStyle.Information, "Export")
End If
End Sub
got it. I added double quotes.
--where=""status='" + status + "' and clientid='" + clientid + "'""

Download template from Sharepoint, save it, close it and then open it via folder where it is saved

I've my templates on a sharepoint and download them. I want it to first save on E.G., my desktop and then close the file and then open the file from the desktop and then do everything from there.
My current code looks like this:
Public Function CH05_Generate()
Dim WordApp As Word.Application
Dim Doc As Word.Document
Dim WordPath As String
WordPath = "Path to the sharepoint"
Set WordApp = CreateObject("Word.Application")
Set Doc = WordApp.Documents.Add(WordPath)
With Doc
.FormFields("text").Result = Forms![TD-E-PM200-CH05]!Kommentar
.FormFields("S3").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q1
.FormFields("S4").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q2
.FormFields("S5").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q3
.FormFields("S6").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q4
.FormFields("S7").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q5
.FormFields("S8").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q6
.FormFields("S9").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q7
.FormFields("S10").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q8
.FormFields("S11").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q9
.FormFields("S12").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q10
.FormFields("S13").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q11
.FormFields("S14").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q12
.FormFields("S15").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q13
.FormFields("S16").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q14
.FormFields("S17").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q15
.FormFields("S18").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q16
.FormFields("S19").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q17
.FormFields("S20").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q18
.FormFields("S21").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q19
.FormFields("S22").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q20
.FormFields("S23").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q21
.FormFields("S24").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q22
.FormFields("S25").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q23
.FormFields("S26").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q24
.FormFields("S27").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q25
.FormFields("S28").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q26
.FormFields("S29").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q27
.FormFields("S30").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q28
.FormFields("S31").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q29
.FormFields("S32").Result = Forms![TD-E-PM200-CH05]!sub.Form!Q30
.FormFields("S33").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q31
.FormFields("S34").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q32
.FormFields("S35").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q33
.FormFields("S36").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q34
.FormFields("S37").CheckBox.Value = Forms![TD-E-PM200-CH05]!sub.Form!Q35
End With
WordApp.visible = True
WordApp.Activate
WordApp.ActiveDocument.Protect wdAllowOnlyFormFields, True
End Function
So I want all the .FormFields to be done in the file that has been open on my desktop and not the Sharepoint.

Connecting datagrid view to database in vb.net

Ok so im trying to display everything in my MYSQL database using a datagrid view. but what i got is not working, can somebody help me with my code
Public Sub dataview()
DataGridView1.DataSource = ""
Dim bindingSource1 As New BindingSource()
Try
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
With Me.DataGridView1
.AutoGenerateColumns = True
bindingSource1.DataSource = cmd
.DataSource = bindingSource1
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.BorderStyle = BorderStyle.Fixed3D
.EditMode = DataGridViewEditMode.EditOnEnter
End With
DataGridView1.DataSource = bindingSource1
Catch ex As Exception
MessageBox.Show("something went wrong")
End Try
You cannot simply pass your MySqlCommand to the BindingSource.
You should use a object of type MySqlDataAdapter to get the command and fill a DataSet/DataTable.
That DataTable/DataSet should be used as DataSource for your bindingSource1
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
Dim da = New MySqlDataAdapter (cmd)
Dim dt = New DataTable()
da.Fill(dt)
bindingSource1.DataSource = dt ' here assign the DataTable'
With Me.DataGridView1
.AutoGenerateColumns = True
.DataSource = bindingSource1
.....
End With
Public Sub dataview()
DataGridView1.DataSource = ""
Dim bindingSource1 As New BindingSource()
Try
Dim cmd As New MySqlCommand("SELECT * FROM upload", db_con)
With Me.DataGridView1
.AutoGenerateColumns = True
bindingSource1.DataSource = cmd
.DataSource = bindingSource1
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.BorderStyle = BorderStyle.Fixed3D
.EditMode = DataGridViewEditMode.EditOnEnter
End With
DataGridView1.DataSource = bindingSource1
Catch ex As Exception
MessageBox.Show("something went wrong")
End Try
try this one^^