This is one way of doing it in VB.NET,
Dim cmd As String = "C:\mysql\bin\MYSQL.EXE --user=root --password=mysupersecretpa
Dim processid As Long = Microsoft.VisualBasic.Inte
Main Topics
Browse All TopicsI have a connection open called dbs in my VB program using MySQL database. I have a SQL file called "tracking.sql" in the C:\ (root) folder. I wish to execute this file through the connection as a batch file but am not having much success. I use the command:
dbs.execute "SOURCE c:\tracking.sql" (having made sure that the file exists in the root folder of course)
...and I get the following error message: You have an error in your SQL syntax. Check the manual ... ... for the right syntax to use near 'SOURCE c:\tracking.sql' at line 1.
Any help would be greatly appreciated. Thanks,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is one way of doing it in VB.NET,
Dim cmd As String = "C:\mysql\bin\MYSQL.EXE --user=root --password=mysupersecretpa
Dim processid As Long = Microsoft.VisualBasic.Inte
Thanks for the suggestions, sorry I hadn't replied before. however, it seems that e-mail notification is not working and I therefore didn't think anyone had made any comments on the question!
vanelk, would this work in VB6?
pshersby, I had considered doing it your way already, but there are several thousand lines of SQL in the file, and I am therefore concerned that the time taken to run through it all across the internet connection would be prohibitive. (I forgot to mention in the question that the MySQL database is sited remotely and linked to via a SSH tunnel.
"vanekl, would this work in VB6?"
There is an equivalent in VB6 that would work in two lines, yes, but I don't know what those two lines are because I don't have VB6 installed.
VB6 has a 'shell' command but it probably has different parameters from what I'm showing in the VB.NET code.
You could try this VB6 code,
(this code found at http://www.users.zetnet.co
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Public Declare Function WaitForSingleObject Lib "kernel32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long _
) As Long
Public Declare Function CreateProcessA Lib "kernel32" ( _
ByVal lpApplicationName As Long, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION _
) As Long
Public Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long _
) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Sub ShellAndWait(ByVal RunProg As String)
Dim RetVal As Long
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
StartInf.cb = Len(StartInf)
RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
RetVal = WaitForSingleObject(proc.h
RetVal = CloseHandle(proc.hProcess)
End Sub
ShellAndWait (cmd)
Business Accounts
Answer for Membership
by: pshersbyPosted on 2004-03-12 at 07:55:28ID: 10581491
I think that SOURCE is actually a command to the mySQL client, not part of the SQL syntax so ODBC cannot pass it and the database engine cannot understand it.
What you need to do is open the file from VB and then loop through:
1- read an SQL statement into a String variable such as sqlCommand
2- do something like dbs.execute sqlCommand
3- loop back to 1 unless you have reached the EOF
4- close the file