Board index » delphi » Multiple datamodules sharing the same database D5Ent

Multiple datamodules sharing the same database D5Ent

If you create a new project, then add a datamodule_main, throw a database
component on it and configure it for MSSQL database (Driver name =mssql,
params contains user/pw/database/server names), set it's database name
property to 'DBMain' and successfully set it's connected property to true,
now create another datamodule called datamodule_x and throw a table on it
and set the database name property to 'DBMain', tablename to a valid table,
and active property to True and it seems to work.  Now close/save the
project and then reopen it and bring up the datamodule_x and it throws a BDE
error with unknown alias for DBMain.   But, if you bring up datamodule_main
and reset the connected property of the database to False (or True..it
doesn't seem to matter) and switch back to datamodule_x and set the active
property of the table to true it doesn't throw an error.  This seems odd,
like I'm cludging Delphi a bit and it's unsettling.  It would probably work
as long as I always remember to bring up the datamodule_main and reset it's
active property first when in design mode.

I've played with sessions and it seems to have the same problems when
dealing with multiple datamodules.  Are we not supposed to share the same
database connection across multiple datamodules?  Is there a better way of
doing this?   With many tables, queries, SP's, etc. on the datamodule I
thought it would be prudent to have separate datamodules but all sharing one
database connection so you could organize the datamodule according to usage,
departments, table types, or whatever.

Suggestions?

Thanks,

Darian

 

Re:Multiple datamodules sharing the same database D5Ent


Darian,

   It is very easy to do what you want.  Reply to me via email and I can
send you an example.

krf
kfrev...@midwayusa.com

Re:Multiple datamodules sharing the same database D5Ent


Quote
Darian Miller wrote in message <39465f82@dnews>...
>If you create a new project, then add a datamodule_main, throw a
database
>component on it and configure it for MSSQL database (Driver name
=mssql,
>params contains user/pw/database/server names), set it's database
name
>property to 'DBMain' and successfully set it's connected property to
true,
>now create another datamodule called datamodule_x and throw a table
on it
>and set the database name property to 'DBMain', tablename to a valid
table,
>and active property to True and it seems to work.  Now close/save the
>project and then reopen it and bring up the datamodule_x and it
throws a BDE
>error with unknown alias for DBMain.   But, if you bring up
datamodule_main
>and reset the connected property of the database to False (or
True..it
>doesn't seem to matter) and switch back to datamodule_x and set the
active
>property of the table to true it doesn't throw an error.

This is perfectly reasonable in design mode. The TTable cannot connect
to a TDatabase component that hasn't been created, and unless you open
datamodule_main, the TDatabase component cannot be created. This is
also true at runtime, datamodule_main must be created first before you
attempt to open datasets connected to it in other modules.

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:Multiple datamodules sharing the same database D5Ent


Hi Kevin
if the example is simple you can share it with us as well (unless you
wnat to increase the volume of your incoming emails, that is <g>).

On Tue, 13 Jun 2000 12:26:21 -0500, "Kevin Frevert"

Quote
<kfrev...@midwayusa.com> wrote:
>   It is very easy to do what you want.  Reply to me via email and I can
>send you an example.

Denis Pyriohos
denis....@usa.net

Re:Multiple datamodules sharing the same database D5Ent


Hi Wayne
of course it is reasonable. In design mode it is also frustrating <g>.
So, the question is "how to arrange my units so DMMain always open
first when I load a project?"

Denis

On Tue, 13 Jun 2000 20:50:33 -0400, "Wayne Niddery (TeamB)"

Quote
<winwri...@chaffhome.com> wrote:
>This is perfectly reasonable in design mode.

Denis Pyriohos
denis....@usa.net

Re:Multiple datamodules sharing the same database D5Ent


Denis,

   Have your main datamodule auto-create and have it the first form in
Project->Options->Forms->Auto-create

Good luck,
krf

Quote
Denis Pyr wrote in message ...
>Hi Wayne
>of course it is reasonable. In design mode it is also frustrating <g>.
>So, the question is "how to arrange my units so DMMain always open
>first when I load a project?"

>Denis

>On Tue, 13 Jun 2000 20:50:33 -0400, "Wayne Niddery (TeamB)"
><winwri...@chaffhome.com> wrote:

>>This is perfectly reasonable in design mode.

>Denis Pyriohos
>denis....@usa.net

Re:Multiple datamodules sharing the same database D5Ent


Denis,

Here you go... <snip>..

 public
    { Public declarations }
    property DatabaseName: string read FDatabaseName write SetDBNames;

procedure TdmYourDataModule.SetDBNames(const Value :String);
var
   x :Integer;
begin
   for x := 0 to (ComponentCount - 1) do
      begin
        if (Components[x] is TQuery) then
           begin
              with (Components[x] as TQuery) do
                 begin
                    Close; {Close query, just in case}
                    DatabaseName := Value;
                 end;
           end;

         if (Components[x] is TStoredProc) then
           begin
              with (Components[x] as TStoredProc) do
                 begin
                    Close;
                    DatabaseName := Value;
                 end;
           end;

      end;
end;
{*************  End of SetDBNames Procedure *****************************}

After you create the datamodule simply set the databaseme name:

YourDataModule.DatabaseName := MainDataModule.MyDatabase.DatabaseName;

Good luck,
krf

Quote
Denis Pyr wrote in message ...
>Hi Kevin
>if the example is simple you can share it with us as well (unless you
>wnat to increase the volume of your incoming emails, that is <g>).

>On Tue, 13 Jun 2000 12:26:21 -0500, "Kevin Frevert"
><kfrev...@midwayusa.com> wrote:

>>   It is very easy to do what you want.  Reply to me via email and I can
>>send you an example.

>Denis Pyriohos
>denis....@usa.net

Other Threads