Entwickler-Ecke

Datenbanken - Access Datenbanken komfortabel ohne Access erstellen


FinnO - Mi 01.07.09 16:44
Titel: Access Datenbanken komfortabel ohne Access erstellen
Hi Leute,

die Frage sollte sich aus dem Titel ergeben: Wie kann man ohne Access eine mdb erstellen?

freue mich über Antworten.


bummi - Do 02.07.09 09:38


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
interface

uses SysUtils, Windows, Forms, Controls, ADODB, ADOX_TLB, JRO_TLB;

var
  sPath : TFileName;

procedure CreateCatalog(AFileName : TFileName; AJetEngineType : Word);

implementation

procedure CreateCatalog(AFileName : TFileName; AJetEngineType : Word);
var
  Catalog    : _Catalog; // the database
  DataSource : String;
begin
  // A spot of housekeeping first up

  if FileExists(AFileName) then
    DeleteFile(PChar(AFileName));

  // Create a catalog (database) object using the provided COM object
  // creation method - no need for wrappers and no need for garbage
  // collection.  All COM objects created will be automatically destroyed
  // when they go out of scope. (The OP compiler adds code to decrement
  // each object's reference count when they go out of scope.  Since creating
  // the object in OP automatically increments its reference count to 1, this
  // ensures that COM will destroy the object because its reference count
  // then equals 0.  Note that the scope is defined by the object's
  // declaration procedure, which is not necessarily where they are created).
  Catalog := CoCatalog.Create;

  // Set the connection string.
  // Note that properties specified in the connection string, such as
  // Jet OLEDB:Engine Type or Jet OLEDB:Encrypt Database are subsequently
  // used in the Catalog.Create method, but not all connection properties are
  // supported.  See the Microsoft Jet 4.0 OLE DB Properties Reference for
  // further details.
  // BTW, Jet Engine Type 5 = Access 2000; Type 4 = Access 97
    { Global Const JET_ENGINETYPE_UNKNOWN = 0
      Global Const JET_ENGINETYPE_JET10 = 1
      Global Const JET_ENGINETYPE_JET11 = 2
      Global Const JET_ENGINETYPE_JET20 = 3
      Global Const JET_ENGINETYPE_JET3X = 4
      Global Const JET_ENGINETYPE_JET4X = 5
      Global Const JET_ENGINETYPE_DBASE3 = 10
      Global Const JET_ENGINETYPE_DBASE4 = 11
      Global Const JET_ENGINETYPE_DBASE5 = 12
      Global Const JET_ENGINETYPE_EXCEL30 = 20
      Global Const JET_ENGINETYPE_EXCEL40 = 21
      Global Const JET_ENGINETYPE_EXCEL50 = 22
      Global Const JET_ENGINETYPE_EXCEL80 = 23
      Global Const JET_ENGINETYPE_EXCEL90 = 24
      Global Const JET_ENGINETYPE_EXCHANGE4 = 30
      Global Const JET_ENGINETYPE_LOTUSWK1 = 40
      Global Const JET_ENGINETYPE_LOTUSWK3 = 41
      Global Const JET_ENGINETYPE_LOTUSWK4 = 42
      Global Const JET_ENGINETYPE_PARADOX3X = 50
      Global Const JET_ENGINETYPE_PARADOX4X = 51
      Global Const JET_ENGINETYPE_PARADOX5X = 52
      Global Const JET_ENGINETYPE_PARADOX7X = 53
      Global Const JET_ENGINETYPE_TEXT1X = 60
      Global Const JET_ENGINETYPE_HTML1X = 70  }

  DataSource := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + AFileName + ';Jet OLEDB:Engine Type=' + IntToStr(AJetEngineType);

  // Create a new Access database
  Catalog.Create(DataSource);
end;


Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt