PDA

View Full Version : @upeters. ODBC Can you explain this to me?


boku
03-28-2009, 01:17 PM
I'm trying to use a button to send a cmd to the sql database, but the following code seems to be giving me troubles.


-- Get ROOT "D:\"
FullSystemPath = Shell.GetFolder(SHF_STARTMENU);
SysRoot = String.Left(FullSystemPath, 3);

-- inData is an input box with a database name which is the sql server
-- in this case its filled with "IHOFFICEDATA" as the database name.
BackUp = Input.GetText("inData");

-- This is the command I'm using, nothing happens.
ODBC.ExecuteSQL("backup database " .. BackUp .. " to disk = '" .. SysRoot .. BackUp .. ".bak' GO");

--I even tried this too, still nothing.
ODBC.ExecuteSQL("BACKUP DATABASE IHOFFICEDATA to disk = 'D:\IHOFFICEDATA.bak' GO")

Any ideas?

presidente
03-28-2009, 04:35 PM
i think the code is wrong. maybe this works:

result = ODBC.ExecuteSQL("BACKUP TABLE IHOFFICEDATA TO 'D:\IHOFFICEDATA.bak'");


i think, things like "to disk" an "GO" are incorrect.

boku
03-28-2009, 09:04 PM
@presidente

You were right about the GO command, cheers, but that was a typo in the post, in the application, it is without the GO command.


BACKUP DATABASE IHOFFICEDATA to disk = 'D:\IHOFFICEDATA.bak'


But I did notice some other typos that I had in the application.

I've just gone through the whole code again, and managed to get it to work!
I've posted the code below for all the see.

Make sure you have an active ODBC connection before using this or it wont work.


-- Get ROOT "D:\" or "C:\" or wherever Windows is installed.
FullSystemPath = Shell.GetFolder(SHF_STARTMENU);
SysRoot = String.Left(FullSystemPath, 3);

-- Database name "IHOFFICEDATA"
BackUp = Input.GetText("inData");

-- The SQL Command
ODBC.ExecuteSQL("backup database " .. BackUp .. " to disk = '" .. SysRoot .. BackUp .. ".bak'");