Problem with DB and CreateProcess

Problem with DB and CreateProcess

Post by David O'Rourk » Sun, 31 Dec 1899 09:00:00



Here's an odd one. I'd appreciate any info anyone has about it.

I have a program that has a TDatabase component and a TQuery connected to an
SQL Server 6.5 DB. The TDatabase is connected when the app starts.

There are several procedures which basically are of the form:

AssignFile(hFile, { My file } );
Rewrite(hFile);

Query1.SQL.Clear;
Query1.SQL.Add( { My query } )
Query1.Open;
Query1.First;

while not Query1.EOF do
begin
    writeln(hFile, { some fields from Query1 } )
    Query1.Next;
end;

Query1.Close;
CloseFile(hFile);

These procedures all work, but although they're all of the same general
form, some of them cause me a problem.

In my program I press a button, all of the above procedures are run, one at
a time to create some text files from the DB tables and then I need to
launch a child process to do something with them.

I'm using CreateProcess, passing nothing in the AppName, and the full path,
exename and parameters in the CmdLine parameter.

This is the crux of the problem here:- My CreateProcess call sometimes fails
with error 87 (Invalid parameter), but only sometimes.
Some of my DB procedures cause it, but not others. I've tried calling the
same procedures several times, not calling them, and in different orders and
all sorts, but that has made no difference. Some procedures cause the
failure and others do not. The problem does not occur if I single step.
And, this is the weird bit, the problem does not occur if I disconnect the
TDatabase component after I've run the text file writing procedures and
before I run the procedure that calls CreateProcess. This is not a
satisfactory way of preventing the error, because the next time the user
wishes to push the button, they will have to log in again.

I cannot see any relationship between CreateProcess and the state of the
TDatabase object, so I'm assuming it's some kind of memory problem, but does
anyone know anything about any of this?

    Any pointers gratefully received.

                            David O'Rourke

 
 
 

Problem with DB and CreateProcess

Post by Rudy Versel » Sun, 31 Dec 1899 09:00:00


Hi David,

(all these newsgroups?<g>)
IMO,
Maybe you should wait untill CreateProcess has finished his job,
before calling the next.

example:

var SI: TStartupInfo; PI:TProgressInformation;
begin
   FillChar(PI,SizeOf(PI),#0);
   FillChar(SI,SizeOf(SI),#0);
   with SI do begin
       cb         := SizeOf(SI);
       dwFlags    := STARTF_USESHOWWINDOW;
       wShowWindow:= SW_SHOW; //SW_HIDE,..
   end;
   if not CreateProcess('C:\.....\myprogram.exe',
                        'myprogram.exe /options',
                         nil, nil, false,
                         NORMAL_PRIORITY_CLASS,
                         nil, nil, SI, PI) then
      raise
      Exception.Create('Error CreateProcess');
      WaitForSingleObject(PI.dwProcessID, INFINITE);
end;

Cheers,

Rudy
====================================================


> Here's an odd one. I'd appreciate any info anyone has about it.

> I have a program that has a TDatabase component and a TQuery connected to an
> SQL Server 6.5 DB. The TDatabase is connected when the app starts.

> There are several procedures which basically are of the form:

> AssignFile(hFile, { My file } );
> Rewrite(hFile);

> Query1.SQL.Clear;
> Query1.SQL.Add( { My query } )
> Query1.Open;
> Query1.First;

> while not Query1.EOF do
> begin
>     writeln(hFile, { some fields from Query1 } )
>     Query1.Next;
> end;

> Query1.Close;
> CloseFile(hFile);

> These procedures all work, but although they're all of the same general
> form, some of them cause me a problem.

> In my program I press a button, all of the above procedures are run, one at
> a time to create some text files from the DB tables and then I need to
> launch a child process to do something with them.

> I'm using CreateProcess, passing nothing in the AppName, and the full path,
> exename and parameters in the CmdLine parameter.

> This is the crux of the problem here:- My CreateProcess call sometimes fails
> with error 87 (Invalid parameter), but only sometimes.
> Some of my DB procedures cause it, but not others. I've tried calling the
> same procedures several times, not calling them, and in different orders and
> all sorts, but that has made no difference. Some procedures cause the
> failure and others do not. The problem does not occur if I single step.
> And, this is the weird bit, the problem does not occur if I disconnect the
> TDatabase component after I've run the text file writing procedures and
> before I run the procedure that calls CreateProcess. This is not a
> satisfactory way of preventing the error, because the next time the user
> wishes to push the button, they will have to log in again.

> I cannot see any relationship between CreateProcess and the state of the
> TDatabase object, so I'm assuming it's some kind of memory problem, but does
> anyone know anything about any of this?

>     Any pointers gratefully received.

>                             David O'Rourke


 
 
 

Problem with DB and CreateProcess

Post by David O'Rourk » Sun, 31 Dec 1899 09:00:00


Thanks for the tip Rudy.

In fact I am waiting for the process to finish, but I was doing it with
repetetive poll to GetExitProcessCode, which is not as efficient as using
WaitForSingleObject. I'll have to try that.

It doesn't really help though. In all, I'm only attempting to call
CreateProcess once and it fails immediately if I have executed any of the
database reads which cause the problem, but not on the others. I'm using D2
at the the mo, but D4 arrived on my desk this AM and I'll put it on ASAP
although I want to get the patches to hand first.  I'm hoping that this will
make the problem go away anyway.

            David.

 
 
 

Problem with DB and CreateProcess

Post by Rudy Versel » Sun, 31 Dec 1899 09:00:00


Hi David,


> Thanks for the tip Rudy.

> In fact I am waiting for the process to finish, but I was doing it with
> repetetive poll to GetExitProcessCode, which is not as efficient as using
> WaitForSingleObject. I'll have to try that.

> It doesn't really help though. In all, I'm only attempting to call
> CreateProcess once and it fails immediately if I have executed any of the
> database reads which cause the problem, but not on the others. I'm using D2
> at the the mo, but D4 arrived on my desk this AM and I'll put it on ASAP
> although I want to get the patches to hand first.  I'm hoping that this will
> make the problem go away anyway.

Databases with problems?

1) Backup and restore your database.
2) Is your SQL (select...) OK?
3) Writeln(F,(...fields...))  You have to read all the fields asString.
   not as IntToStr(....asInteger) or something as that.
4) you can use:
       try
           SQL...
       except
           on e:eDBEngineError do ...
       end;
   (look at other post here "Get specific error message and text?How?")

Hope this helps you,

Rudy

 
 
 

1. Permissions problem with ADOX and CreateProcess() on WinXP Pro

I have a DLL created with MSVC 6 that uses ADOX to create a database.
This DLL is called by a third party app, which is in turn launched by
my VB 6 app using CreateProcess().  When the DLL attempts to create
the database:

        TESTHR(hr = m_pCatalog.CreateInstance(__uuidof (ADOX::Catalog)));
        m_pCatalog->Create(bstrConn);

I get a _com_error exception at the Create() call:

        COM error #: -2147467262
        COM error source: Provider
        COM error desc: No such interface supported

Here's the VB code:

        Dim pi As PROCESS_INFORMATION
        Dim si As STARTUPINFO
        Dim sa As SECURITY_ATTRIBUTES
        dim lRes As Long

        ' Init the STARTUPINFO struct
        si.dwFlags = STARTF_USESHOWWINDOW
        si.wShowWindow = SW_SHOWDEFAULT
        si.cb = LenB(si)
        ' Init the SECURITY_ATTRIBUTES
        sa.nLength = LenB(sa)
        sa.bInheritHandle = False
        sa.lpSecurityDescriptor = 0
        ' Call the Win32 API function CreateProcess
        ' strExe is a String that contains the path and filename of the
        ' executable.  strDir contains the path.
        lRes = CreateProcess(vbNullString, strExe, sa, sa, True, _
                0, vbNull, strDir, si, pi)

Conditions:

  o If I launch the third party .exe directly (by doubleclicking on it
    or running it from the commandline) it works perfectly

  o I am running it under a user ID that is a member of the
    Administrators group and has rights to the entire HD

  o The problem does not occur under Windows 2000 Pro (also using
    Admin member user ID)

  o The XP box has MDAC 2.7, the Win2K boxes have MDAC 2.6

Help!

--
Charles Calvert             |  Software Design/Development
Celtic Wolf, Inc.           |  Project Management
http://www.celticwolf.com/  |  Technical Writing
(703) 580-0210              |  Research

2. RegSvr32

3. 'CreateProcess' problem

4. NEWBIE: Clustering Architecture

5. Permissions problem with ADOX and CreateProcess() on WinXP Pro

6. SqlServer administration book

7. Help About createprocess

8. HELP Need Reflex Program

9. Error in .exe if its launched with CreateProcess

10. API CreateProcess and further child fails

11. Need To Customize CreateProcess Task at Run Time

12. textcopy via cmd verse in c++ with CreateProcess or WinExec

13. CreateProcess osql in VB6