Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access violation in module MSDART.DLL

Posted on 2004-09-11
7
1,541 Views
Last Modified: 2012-06-21
I have a Delphi program accessing a MS/SQL database.
I initially used the BDE to access it and everything ran fine.
For technical reasons too long to explain here, I have decided to 'migrate' the program to ADO components.
And here I have some problems.
The migrations was of course very simple, moving to TADOconnection etc...
But at execution, I first got a problem that CoInitialize was not performed, so after searching, I found I had to insert a CoInitialize(nil) instruction before to invoke these AFO objects.
But now, just before to terminate, the program issues an access violation in module MSDART.DLL. (I get this when running if from the Delphi development environment)
What the program does is
1. connect to the database
2. read some data in a table via a stored procedure
3. write some of this data to the standard output (writeln(text))
4. terminate
The data is correctly written to the standard output (the console) but an addition info is written there : runtime error 216.
Please help !
0
Comment
Question by:LeTay
7 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12034473
Where is your TADOConnection? On a form or DataModule? Long time ago I had the same problem, but when the ADO Connection was moved to data module - it was fine...
0
 

Author Comment

by:LeTay
ID: 12042031
Neither on a form nor on a datamodule
I just create it at run time
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12044843
The problem you're having is that you don't free any interface variable that gets initialized in your code. I've had the same problem and solved it like this:

program EnumADSI;

uses WhateverYouNeedToUse;

procedure ProcessDatabase;
begin
  // Whatever
end;

begin
  if Succeeded(CoInitializeEx(nil, COINIT_MULTITHREADED or COINIT_DISABLE_OLE1DDE or COINIT_SPEED_OVER_MEMORY)) then begin
    try
      // Call some procedure here that will do all the work with your database.  
      ProcessDatabase;
    except on E: Exception do WriteLn(E.Message);
    end;
    CoUninitialize;
  end;
end.

Whatever you do, try avoiding the use of global interface variables since Delphi is a bit lazy trying to clean them.

And don't forget to call CoUninitialize...

The runtime error just occurs because Delphi is trying to clean up some interfaces but for whatever reason they got messed up during the finalization.
0
 

Author Comment

by:LeTay
ID: 12063519
The remark of Ivanov (moving to a tdatamodule) looks going in the same direction that alex remark : some clean-up is not ... clean.
But now look at this :
I wrote this simple console application (I put some .../... on unuseful lines for this purpose) where there is nothing special done at the end (no couninitialize) and ... it works fine !
I think I need to have an indepth look at the code (much longer) that has the exception...
Here is the working code :
program P1;

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ADODB, DB, ActiveX;
{$R *.res}
var
 DB1:TADOConnection;
function ADOConnectSQL(DB1:TADOConnection):boolean;
begin
 with DB1 do
  begin
   ConnectionString  := .../...
   ConnectionTimeout := 15;
   CommandTimeout    := 300;
   KeepConnection    := True;
   LoginPrompt       := False;
  end;
 try
  DB1.Open;
  Writeln('DB open successful');
 except
  Result := False;
  Writeln('DB open failed');
  Exit;
 end;
 Result := True;
end;
procedure ADOGetSQL;
var
 Temp:string;
 SP:TADOStoredProc;
begin
 SP := TADOStoredProc.Create(Application);
 with SP do
  begin
   SP.Connection := DB1;
   ProcedureName := .../...;
   Parameters.Clear;
  end;
 with SP do
  begin
   Parameters.CreateParameter(.../...);
   try
    Prepared := True;
    ExecProc;
    Temp := Parameters.ParamByName(.../...);
    Free;
   except
    Exit;
   end;
  end;
 Writeln('DB data is ' + Temp);
end;
begin
 CoInitialize(nil);
 DB1 := TADOConnection.Create(Application);
 if ADOConnectSQL(DB1) then ADOGetSQL;
 DB1.Free;
end.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13432786
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
Help on project with Soap 10 57
Delphi: making a BW image transparent 10 60
shape, triangle, dbctrlgrid 3 17
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question