2

i am trying to execute 2 scripts using inno setup. The problem i think is the path of the file that contains spaces. The scripts are working because i already tried the hardcoded path with no spaces and it does work. there is this post where this problem is discribed and a solution is added but i have tried and it doesnt work. this is the topic Inno Setup, spaces and double quote in [Run]

in order not to use hardcoded paths i am using inno setup constants, so on the output folder i have a setup.exe and and folder called testfolder with the 2 scripts, one is for creating a database, and the other is to create the tables. in inno setup did this

connExe:=ExpandConstant('{tmp}')+'\sqlcmd.exe';
pathFx1:=ExpandConstant('{src}')+'\testfolder\teste.sql';
pathFx2:=ExpandConstant('{src}')+'\testfolder\idontimedb.des';
Exec(connExe,' -S DEV3\IDONICSYS4 -U sa -P idsysadmin -i \""'+connFx1+'\""', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
MsgBox(IntToStr(ResultCode), mbError, mb_Ok);
Exec(connExe,' -S DEV3\IDONICSYS4 -d MSSQLTIPS -U sa -P idsysadmin -i \""'+connFx2+'\""', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
MsgBox(IntToStr(ResultCode), mbError, mb_Ok);

when i run both messages boxs show code 2,but i am still unable to find what does this code means. I think my problem is with the backslash and the quotation marks position , but i have already tried different combination and it doesnt work.. Thanks for the help.

the full path of the files are: C:\Users\hsilva\Documents\Inno setupo scripts\Setup\Output\testfolder\teste.sql \create database

C:\Users\hsilva\Documents\Inno setupo scripts\Setup\Output\testfolder\idontimedb.des \create tables

C:\Users\hsilva\Documents\Inno setupo scripts\Setup\Output\setup.exe \executable

thanks in advance...

UPDATE - 27/10/2014 so as user LTama sugested(thanks once again TLama) i have checked the files that were needed for running the scripts.. and the files needed were commented,i made a few changes and now it is giving me code 1.What does it mean? i use the code found in this site http://0x3f.org/blog/howto-execute-sql-scripts-in-inno-setup/ and made a few changes.

in the files section i have got this:
Source: "C:\Users\hsilva\Documents\InnoSetup\sqlcmd.exe";  Flags: dontcopy ; 
Source: "C:\Users\hsilva\Documents\InnoSetup\sqlcmd.rll";  Flags: dontcopy  ; 

Do i need to have these 2 files, because when installing sql server 2008 r2, these files are installed , and available?

in the code section i have got this:

procedure DeinitializeSetup();
var
connExe:String;
connFx1:String;
begin
 ExtractTemporaryFile('sqlcmd.exe');
 ExtractTemporaryFile('sqlcmd.rll');
 connExe:=ExpandConstant('{tmp}')+'\sqlcmd.exe';
 connFx1:=ExpandConstant('{src}')+'\folder\teste.sql';
 Exec(connExe,' -S DEV3\IDONICSYS4 -U sa -P idsysadmin -i \""'+connFx1+'\""', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
 MsgBox(IntToStr(ResultCode), mbError, mb_Ok);
end;
end;

this is execute in the end of setup, i ommited some of the checks like checking if the instance exists..

Community
  • 1
  • 1
Hugo Silva
  • 352
  • 8
  • 26
  • Exit code 2 stands for [`ERROR_FILE_NOT_FOUND`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx#ERROR_FILE_NOT_FOUND). Are you extracting sqlcmd.exe into the `{tmp}` folder ? – TLama Oct 27 '14 at 11:08
  • so during the test i commented some line and the sqlcmd.exe and sqlcmd.rll lines were commented. i have updated the post. – Hugo Silva Oct 27 '14 at 12:00
  • I don't think those files are redistributable. You should use either those from an existing SQL Server installation, or those you install with the SQL Server distribution. So I think that your task is rather finding a path to an existing sqlcmd.exe tool. – TLama Oct 27 '14 at 12:19
  • it is working now, so i dont need the backslash, i just need to add the quotation marks before and after the file path..i am currently changing the script to fetch these 2 files sqlcmd.exe and sqlcmd.rll from the program files folder.. – Hugo Silva Oct 27 '14 at 12:22
  • What if the user chooses to install SQL Server to a [`different location`](http://msdn.microsoft.com/en-us/library/ms143547.aspx) ? – TLama Oct 27 '14 at 12:27
  • you have got a point there, when running setup i am doing a quiet simple installation of sql server(the user sees the current status of installation but doesnt manipulate the installation), so the sql server will be installed in the program files folder..if sqlserver is already installed the only way i can think is searching in the regedit the path and go from there.. – Hugo Silva Oct 27 '14 at 12:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63704/discussion-between-hugo-silva-and-tlama). – Hugo Silva Oct 27 '14 at 12:55

1 Answers1

0

here what i think.. 1. Does the command work outside of Inno Setup Script?

  1. Use LOG(); to test the string pass to exe in a command window.

  2. Extract the teste.sql to {tmp}

Source: "C:\Users\hsilva\Documents\InnoSetup\teste.sql"; Flags: dontcopy ;

    function CustomForm_NextButtonClick(Page: TWizardPage): Boolean;


 var
    connExe:String;
    connFx1:String;
    connTxt:String;
    ResultCode: Integer;

    begin
    // need to sql server in dropdown list 
    //  sqlcmd -L > text.txt
        ExtractTemporaryFile('sqlcmd.rll');
        ExtractTemporaryFile('sqlcmd.exe');
        connExe:=ExpandConstant('{tmp}')+'\sqlcmd.exe';
        connTxt := ' -S ' + lstSqlServer.text + ' -U '+ txtUsername.Text + ' -P ' + txtPassword.Text + ' -Q "CREATE DATABASE ' + txtDatabase.Text + '"' + ' -o ' + 
    // use log to view and test the string in a command window
       Log('The Value is connTxt: ' + connTxt );
        if Exec(connExe, connTxt, '' , SW_HIDE, ewWaitUntilTerminated, ResultCode)     then
    begin
      //MsgBox(IntToStr(ResultCode), mbError, mb_Ok);
      ExtractTemporaryFile('onestep2012.sql');
      connFx1:=ExpandConstant('{tmp}\OneStep2012.sql');
      connTxt := ' -S ' + lstSqlServer.text + ' -U '+ txtUsername.Text + ' -P ' + txtPassword.Text + ' -d ' + txtDatabase.Text + ' -i ' + connFx1 + ' -o ' + ExpandConstant('{tmp}\log.log');
      Log('The Value is connTxt: ' + connTxt );
      if Exec(connExe, connTxt, '' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
      begin
      MsgBox( 'The '+ txtDatabase.Text + ' OneStep Database is ready for use' , mbInformation, mb_Ok);
      result := True;
      end;
     end;
    end;
hram908
  • 374
  • 6
  • 15