Is this another unsolved mystery? -An error occurred while using adodataset in DLL.

Source: Internet
Author: User
Is this another unsolved mystery? --- Problems with using adodataset in dll: Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061128102336156.html
The previous post is searched and no useful information is found.

Md. After one day, the headers are too big and the cause is still not found:
In DLL, I declare global ADO: TADODataSet;
DLL load is also available
Coinitialize (NiL );
ADO: = TADODataSet. Create (NiL );
However, when reading a record,
Ado. commandtext: = 'select text from menus where id = '+ inttostr (menuid );
Ado. open;
N: = ADO. recordcount;
Or ADO. recno: = 1;

Master Program When this DLL is called, sometimes the memory address error is reported when it comes to the last two items, but sometimes there is no. there is a mistake. In severe cases, the main program will exit !!!
Use datamoudle. the problem persists !!!
Why ???

You can use sharemem to place it in the first use order of DLL and DLL.

Agree to the upstairs. In addition, if it is not multi-thread, there is no need to add coinitialize (NiL); this sentence may also cause address errors.

Bangding

It's been earlier than sharemem.
Useless.

Coinitialize (NiL) is not used for compilation.

Not so many fans. LZ F1 helps solve all LZ problems ~~

This exception is very strange. Sometimes, even opening the QQ dialog box may also lead to an error!
Or open another software or file, it also causes the error, and all the errors are voiced when accessing the ADO object !!!!
Difficult to solve

In this case, LZ writes ADO: = TADODataSet. Create (NiL); when it is created, it writes it to the exception to capture

ADO: = TADODataSet. Create (NiL );
Try
Execute ADO to read dataCode
Finally
Ado. Free;
And;

Dizzy... please look at the question and answer it again, bro !!
When creating an object, there is no problem at all. Besides, sometimes it works normally?

It may be due to the problem of adoconnection of ADO connection in DLL. If adoconnection is placed in the data module and the data module is also placed in the DLL, this will definitely cause an error. If this is the case, you must explicitly create a data module when loading the DLL.

I made a complete demo for you and tested it for 1000 consecutive times. OK.

Uses
Sysutils,
ActiveX,
ADODB,
Classes;

{$ R *. Res}

Function dataexport: integer;
VaR
Adoconnection: tadoconnection;
Adodataset: TADODataSet;
Begin
Coinitialize (NiL );
Adoconnection: = tadoconnection. Create (NiL );
Adoconnection. connectionstring: = 'provider = sqloledb.1; persist Security info = false; user id = sa; initial catalog = Wangs; Data Source = .';
Adoconnection. loginprompt: = false;
Adodataset: = TADODataSet. Create (NiL );
Adodataset. Connection: = adoconnection;
Try
Adodataset. close;
Adodataset. commandtext: = 'select * From twangs_userinfo ';
Adodataset. open;
Result: = adodataset. recordcount;
Finally
Adodataset. Free;
Adoconnection. Free;
Couninitialize;
End;
End;

Exports
Dataexport;

Begin
End.

Laifeng:
1. Do I have to use adodataset. Connection? Is that the crux of the problem?
2. Can I replace other ADO objects with global ones?

1. Do I have to use adodataset. Connection? Is that the crux of the problem? (Not tested)

2. Can I replace other ADO objects with global ones? Yes (tested)

1. Do I have to use adodataset. Connection? Is that the crux of the problem? Yes (just tested)

The crux of the problem should be

Couninitialize;

However, I suggest you follow the above specifications. All of my systems involve these components. Long-time sandground. Haha

Couninitialize;
I tried it n times, and sometimes an error is reported if I did not add this item.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.