Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 18 total
Thread Create table at runtime
Mon, Jul 17 2017 7:24 PMPermanent Link

KimHJ

Comca Systems, Inc

I'm creating a EWB module and in a thread I'm trying to Create a EDBTable but as soon as I open it I get an access violation.

The AppSession and the AppDataBase is placed on Unit1.

Uses
edbcomps,
 DB;
implementation
uses
   unit1;

procedure SendThread.Execute;
var
MyTable: TEDBTable;

MyTable := TEDBTable.Create(nil);
With MyTable do
            begin
                    DatabaseName := 'AppData';
                    SessionName := 'Comca';
                    TableName := 'Customer';
                    Readonly := True;
                    IndexFieldNames := 'ID';
                    Open;
                    First;
                    While (not MyTable.Eof) do
                              begin
                                       // code here
                                      Next;
                              end;
                   Close;
                   Free;
            end;         

I tried to search the Forum but most tables are created using SQL.

Thanks,
Kim
Tue, Jul 18 2017 1:16 AMPermanent Link

Adam H.

I have no idea if I'm right but is it possible to create a table with a nil owner, or does it require a control?

I'd try changing:

MyTable := TEDBTable.Create(nil);

to

MyTable := TEDBTable.Create(Self);

and see if that resolves the issue.

(I'm probably wrong, but something to try while you're waiting for someone more knowledgeable than me to respond Smile)

Cheers

Adam.
Tue, Jul 18 2017 3:22 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

KimHJ


If this is being created in a thread then you may have trouble later on anyway since you're not maintaining full isolation. Have a read of this section in the pdf manual "4.3 Multi-Threaded Applications"

Where are the session & database created - are they created before you try and open the table?


Roy Lambert
Tue, Jul 18 2017 4:25 AMPermanent Link

Matthew Jones

Roy Lambert wrote:

> thread

Good point. Here is my code that I use from all my threads:

function PrepareSession(stMode : TSessionType) : TEDBSession;
begin
   Result := TEDBSession.Create(nil);
   Result.AutoSessionName := true;
   Result.LocalConfigPath := g_xStartupConfig.DatabasePath;
   case stMode of
   SESSION_ADMIN:
      begin
         Result.LoginUser := 'Administrator';
         Result.LoginPassword := 'EDBDefault';
      end;
   SESSION_STANDARD:
      begin
         Result.LoginUser := 'Something';
         Result.LoginPassword := 'another';
      end;
   else //    SESSION_READONLY:
      begin
         Result.LoginUser := 'ReadOnly';
         Result.LoginPassword := 'yeahright';
      end;
   end;
//   Result.LocalEncryptionPassword := GetPassword;
   Result.Open;
end;

procedure TProductQuery.PrepareDatabase;
begin
   if not assigned(m_xThreadSession) then
   begin
      m_xThreadSession := PrepareSession(SESSION_STANDARD);
   end;
end;


function TProductQuery.PrepareQuery: TEDBQuery;
begin
   PrepareDatabase;

   Result := TEDBQuery.Create(nil);
   Result.SessionName := m_xThreadSession.SessionName;
   Result.DatabaseName := g_xStartupConfig.DatabaseName;
end;


procedure TProductQuery.FixProducts;
var
   xWorkQuery : TEDBQuery;   // query used to find info
begin
   xWorkQuery := nil;
   try
      xWorkQuery := PrepareQuery;
....

--

Matthew Jones
Tue, Jul 18 2017 4:53 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Kim


In the binaries newsgroup
Message-ID: <52BA3A3F-C46E-4012-9985-09B894FAFF3B@news.elevatesoft.com>
Date: Sat, 30 Nov 2013 12:51:42 +0000
Subject: Roy Lambert's Tnlhxxx stuff

In Homebrew.zip you'll find a unit nlhEDB - this contains the code I use to do this sort of thing.

Roy Lambert
Tue, Jul 18 2017 4:53 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Matthew


Oh good we now have all your passwords - hacking here we come.

Roy Lambert
Tue, Jul 18 2017 5:11 AMPermanent Link

Matthew Jones

Roy Lambert wrote:

> passwords

Aaargh!

8-)

--

Matthew Jones
Tue, Jul 18 2017 10:29 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Kim,

<< I'm creating a EWB module and in a thread I'm trying to Create a EDBTable but as soon as I open it I get an access violation. >>

As pointed out, you need to keep the session, database, and dataset components (table, query, stored proc/func, script) isolated from other threads, per this information:

https://www.elevatesoft.com/manual?action=viewtopic&id=edb2&product=rsdelphiwin32&version=10T&topic=Multi_Threaded_Applications

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Jul 18 2017 1:05 PMPermanent Link

KimHJ

Comca Systems, Inc

Tim Young [Elevate Software] wrote:

>>As pointed out, you need to keep the session, database, and dataset components (table, query, stored proc/func, >>script) isolated from other threads, per this information:

Thanks to everyone.

I was just surprised that I need to create a session and database since you could have unlimited number (I don't know if there is a limited) of dataset's connected to the same Sessions and Database.

I can drop a Session and a Database and 50 Dataset on a form and have all 50 connect to the same table and all 50 using a different index.

Thanks
Kim
Tue, Jul 18 2017 2:37 PMPermanent Link

KimHJ

Comca Systems, Inc

"Matthew Jones" wrote:

>>Good point. Here is my code that I use from all my threads:

function PrepareSession(stMode : TSessionType) : TEDBSession;
   begin
   Result := TEDBSession.Create(nil);
   Result.AutoSessionName := true;
   Result.LocalConfigPath := g_xStartupConfig.DatabasePath; <<

Matthew I'm a little confused about the AutoSessionName.
I thought the SessionName always have to be the name of the Session you had created in ElevateDB Manager.

I see you then add a LocalConfigPath is this instead of the SessionName?

Since I connect Remote and not Local would I still be able to use AutoSessionName?

I have twenty different databases in my session and when a request is sent to the module it change to the database associated with the login.

How will I be able to extract the localConfigPath for the session since I use a sessionname for connecting?
I check my Session when the it connect and the LocalSessionPath is blank.

Thanks,
Kim
Page 1 of 2Next Page »
Jump to Page:  1 2
Image