Board index » delphi » Creating and Access DB on-the-fly

Creating and Access DB on-the-fly

I'm trying to re-program a Visual Basic application to Dephi 3.  In my VB
application, I create an Access DB with three tables using the DAO (jet)
object.  I did it this way so that I could update the program without
having to provide blank database and tables created externally.

Is there anyway I can do this using Delphi 3 and the BDE.  Visual basic is
such a Walrus for my application.  The mscomm component can't even keep up
with a 4800 baud NMEA 0183 serial data stream, and that's before my program
processes the data.

I know how to manipulate an existing Access database, but not how to create
one in code.  Any help greatly appreaciated.

        Mike Simpson

 

Re:Creating and Access DB on-the-fly


Quote
Michael R. Simpson wrote:

> I'm trying to re-program a Visual Basic application to Dephi 3.  In my VB
> application, I create an Access DB with three tables using the DAO (jet)
> object.  I did it this way so that I could update the program without
> having to provide blank database and tables created externally.

> Is there anyway I can do this using Delphi 3 and the BDE.  Visual basic is
> such a Walrus for my application.  The mscomm component can't even keep up
> with a 4800 baud NMEA 0183 serial data stream, and that's before my program
> processes the data.

> I know how to manipulate an existing Access database, but not how to create
> one in code.  Any help greatly appreaciated.

>         Mike Simpson

Have a look at the Delphi Local SQL help namely CREATE TABLE, ALTER
TABLE, data manipulation stuff.  Also have a look at the same statements
in the Access help as the SQL statements have to be syntactically
correct for Access.  Something like the following will make you a table
in access
CREATE TABLE NewTable
                (FieldOne TEXT, FieldTwo TEXT,
                 ,...., FieldN DATATYPE);

Also need to add index and key information into the definition but this
is all pretty well documented.  Hope this helps.

Jody.

Re:Creating and Access DB on-the-fly


I got this code from another user but I have not tested it.

...............cut here ......................
const
  dbLangGeneral = $0409; {default language, English and related}

  {version and encryption options}
  dbVersion10 = 1;
  dbEncrypt = 2;
  dbDecrypt = 4; {only used when packing}
  dbVersion11 = 8;
  dbVersion20 = 16;
  dbVersion30 = 32; {choose this for Access 95 database}

procedure CreateJetDatabase(const FileName: string;
  Locale: integer; options: integer);
var
  DBEngine: Variant;
  Workspace: Variant;
begin
  DBEngine := CreateOleObject('DAO.DBEngine');
  Workspace := DBEngine.Workspaces[0];
  Workspace.CreateDatabase(Filename, $409, Options);
end;

Bill

(Sorry but TeamB cannot answer support questions received via email.)
(To send me email for any other reason remove .nospam from my address.)

Re:Creating and Access DB on-the-fly


Quote
>I'm trying to re-program a Visual Basic application to Dephi 3.  In my VB
>application, I create an Access DB with three tables using the DAO (jet)
>object.  I did it this way so that I could update the program without
>having to provide blank database and tables created externally.

>Is there anyway I can do this using Delphi 3 and the BDE.

If you are looking  to create a .mdb file you can do it.  Sample code
follows.  Tables can be created in Delphi with CreateTable and with
SQL

.................
const
  dbLangGeneral = ';LANGID=0x0409;CP=1252;COUNTRY=0';

  {version and encryption options}
  dbVersion10 = 1;
  dbEncrypt = 2;
  dbDecrypt = 4; {only used when packing}
  dbVersion11 = 8;
  dbVersion20 = 16;
  dbVersion30 = 32; {choose this for Access 95 database}

procedure CreateJetDatabase(const FileName: string;
  Locale: String; options: integer);
var
  DBEngine: Variant;
  Workspace: Variant;
begin
  DBEngine := CreateOleObject('DAO.DBEngine');
  Workspace := DBEngine.Workspaces[0];
  Workspace.CreateDatabase(Filename, locale, Options);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CreateJetDatabase('blip3.mdb',dblangGeneral,dbEncrypt )
end;

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:Creating and Access DB on-the-fly


Brian Bushay TeamB <BBus...@DataGuidance.com> wrote in article
<34e78d72.38835...@forums.borland.com>...

Quote

> procedure CreateJetDatabase(const FileName: string;
>   Locale: String; options: integer);
> var
>   DBEngine: Variant;
>   Workspace: Variant;
> begin
>   DBEngine := CreateOleObject('DAO.DBEngine');
>   Workspace := DBEngine.Workspaces[0];
>   Workspace.CreateDatabase(Filename, locale, Options);
> end;

Brian:  
Thanks for the reply (as well as the other responders to my plea for help).
 I tried the above code ( with JET DAO 3.5) and got an Ole error when
creating the OLE object.  Upon examining the registry I found a
'DAO.DBEngine.35' label and when I substituted it for the DAO.DBEngine
param, my program made more progress.  It then crashed at the
CreateDatabase line with an error: "Unable to find installable ISAM".
Since the Access .MDB database file is not part of the ISAM file list, I
have to assume that the JET object is mixed up about the creation of the
desired database type.  The workspase and createdatabase calls are similar
to those I used in VB, so the culprit is probably the CreateOleObject code
but I'm not sure why.  I have both VB 5.0 and Access 97 on my computer and
they are properly registered.  Any further help appreciated..

                Michael Simpson

Re:Creating and Access DB on-the-fly


Bill Todd (TeamB) <Bill_T...@compuserve.com.nospam> wrote in article
<34da7ed6.16237...@forums.borland.com>...

Quote
> procedure CreateJetDatabase(const FileName: string;
>   Locale: integer; options: integer);
> var
>   DBEngine: Variant;
>   Workspace: Variant;
> begin
>   DBEngine := CreateOleObject('DAO.DBEngine');
>   Workspace := DBEngine.Workspaces[0];
>   Workspace.CreateDatabase(Filename, $409, Options);
> end;

Bill:
Thanks for the reply (as well as the other responders to my plea for help).
 I tried the above code ( with JET DAO 3.5) and got an Ole error when
creating the OLE object.  Upon examining the registry I found a CLSID
'DAO.DBEngine.35' label and when I substituted it for the DAO.DBEngine
param, my program made more progress.  It then crashed at the
CreateDatabase line with an error: "Unable to find installable ISAM".
Since the Access .MDB database an installable ISAM, I
have to assume that the JET object is mixed up about the creation of the
desired database type.  The workspase and createdatabase calls are similar
to those I used in VB, so the culprit is probably the CreateOleObject code
but I'm not sure why.  I have both VB 5.0 and Access 97 on my computer and
they are properly registered.  Any further help appreciated..

                Michael Simpson

Re:Creating and Access DB on-the-fly


Quote
>he workspase and createdatabase calls are similar
>to those I used in VB, so the culprit is probably the CreateOleObject code
>but I'm not sure why.  I have both VB 5.0 and Access 97 on my computer and
>they are properly registered.  Any further help appreciated..

The CreateOleObject needs ComObj in the USES of the unit where you use
it.  Beyond that all I can tell you is I have personaly tested the
code and it works for me.  I have Access97 installed on my machine.

--
Brian Bushay (TeamB)
Bbus...@DataGuidance.com

Re:Creating and Access DB on-the-fly


Brian Bushay TeamB <BBus...@DataGuidance.com> wrote in article
<34dd1070.37425...@forums.borland.com>...

Quote

> The CreateOleObject needs ComObj in the USES of the unit where you use
> it.  Beyond that all I can tell you is I have personaly tested the
> code and it works for me.  I have Access97 installed on my machine.

Thanks for the Reply Brian.  I'm stumped! Yes I had the USES ComObj ,  I've
tried the program on both my work and home computers (200 MMX win95
machines) and on both machines I get a raised exception 'Ole error
80040112' when I hit the CreateOleObject line of code.  I Don't know what
that error number references?

                Michael Simpson

Re:Creating and Access DB on-the-fly


Brian Bushay TeamB <BBus...@DataGuidance.com> wrote in article
<34dd1070.37425...@forums.borland.com>..

.

Quote
> The CreateOleObject needs ComObj in the USES of the unit where you use
> it.  Beyond that all I can tell you is I have personaly tested the
> code and it works for me.  I have Access97 installed on my machine.

Whoa!  I Tried your code (with the full Lang specifier: dbLangGeneral =
';LANGID=0x0409;CP=1252;COUNTRY=0';) using DBEngine := CreateOleObject
('DAO.DBEngine.35'); and it WORKED:  I thought I had tried that combo but
apparantly not.  Thanks a lot.  (for some reason it still does not work
using the 'DAO.DBEngine' CLSID.

                        Thanks much
                                Michael Simpson

Other Threads