怎么我有D里面没有这个东西???想让它创建SQLdmo.pas  可是D里面没有这个ActiveX sqlmdo文件,不知道怎么回事,以前装的D里面都有的~

解决方案 »

  1.   

    If you have Enterprise manager (SQL Server tools) installed on the machine, you may activate any Enterprise Manager function or menu from within your appliction using SQLNS and SQLDMO. 
    The good thing is it is easy to make backup as well as restore since it works exactly the same way as using the Enterprise manager. The downside is it will only work if the tools are installed on the client machine.
    1) Choose project, Import typelibrary.
    2) Look for "Microsoft SQLNamespace Object Library" in the list.
    3) Choose install or create unit depending on if you want it as a component or just access using TLB unit as I have.
    4) Include SQLNS.pas in uses of your unit.
    5) Now do the same 4 steps with "Microsoft SQLDMO Object library" (SQLDMO.pas)
    First operation is then to connect to the SQL server...
    uses
    SQLNS, SQLDMO;
    var
    FNameSpace:SQLNamespace; // This one needs to be global or part of class as it needs to be accessed by other functions.
    var
    ConString:OLEVariant;
    Hnd:Integer;
    FServerName, FPass, FUser: String;
    // strings are to be assigned with the password, username and servername to then make part of connection string...
    ConString:='Server='+FServerName+';UID='+FUser+';PWD='+FPass+';Trusted_Connection=No';
    // The connect operation also requires a window handle. As I had this call within a component I used the one below. If you have a form then Hnd:=Form.Handle instead.
    Hnd:=(Owner as TWinControl).Handle;
    // Now make the connection...
    FNameSpace:= CoSQLNamespace.Create;
    FNameSpace.Initialize(FAppName,SQLNSRootType_Server,ConString,Hnd);
    // Include the function below to navigate easy in the namespace...
    function GetDBNameSpaceObject(
    const aDBName: String): SQLNamespaceObject;
    var
    hServer,hDatabases,hDatabase:Integer;
    begin
    Result:=nil;
    hServer:=FNameSpace.GetRootItem;
    hDatabases:=FNameSpace.GetFirstChildItem(hServer,SQLNSOBJECTTYPE_DATABASES,'');
    hDatabase:=FNameSpace.GetFirstChildItem(hDatabases,SQLNSOBJECTTYPE_DATABASE,aDBName);
    Result:=FNameSpace.GetSQLNameSpaceObject(hDatabase);
    end;
    // Now you may use this function to activate the "database backup menu" for a particular database on the server...
    procedure ShowBackupDB(const aDBName: String);
    var
    DB:SQLNamespaceObject;
    Hnd:Integer;
    begin
    Hnd:=(Owner as TWinControl).Handle;
    DB:=GetDBNameSpaceObject(aDBName);
    DB.ExecuteCommandByID(SQLNS_CmdID_DATABASE_BACKUP,Hnd,0);
    DB:=nil;
    end;
    // To show "restore menu", use this procedure...
    procedure ShowRestoreDB(const aDBName: String);
    var
    DB:SQLNamespaceObject;
    Hnd:Integer;
    begin
    Hnd:=(Owner as TWinControl).Handle;
    DB:=GetDBNameSpaceObject(aDBName);
    DB.ExecuteCommandByID(SQLNS_CmdID_DATABASE_RESTORE,Hnd,0);
    DB:=nil;
    end;
    // To make a backup without showing any interface, use this procedure...
    {
    RestoreType=SQLDMORestore_Database,
    SQLDMORestore_Files,
    SQLDMORestore_Log
    DeviceName=Valid name of a backup-device
    }
    procedure RecordBackup(const aDBName: string;
    BackupType: SQLDMO_BACKUP_TYPE; const DeviceName: string;
    Initialize: Boolean);
    var
    ThisBackup:_Backup;
    begin
    try
    ThisBackup:=coBackup.Create;
    except
    Messagedlg('coBackup.Create failed, the object might not be installed on this machine',mtError,[mbOK],0);
    end;
    ThisBackup.Initialize:=Initialize;
    ThisBackup.Database:=aDBName;
    ThisBackup.Devices:='['+DeviceName+']';
    ThisBackup.SQLBackup(FServer);
    ThisBackup:=nil;
    end;
    // To restore without interface, use this procedure...
    procedure TNSConnection.RestoreBackup(const aDBName: string;
    RestoreType: SQLDMO_RESTORE_TYPE; const DeviceName: string);
    var
    ThisRestore:_Restore;
    begin
    try
    ThisRestore:=coRestore.Create;
    except
    Messagedlg('coRestore.Create failed, the object might not be installed on this machine',mtError,[mbOK],0);
    end;
    ThisRestore.Database:=aDBName;
    ThisRestore.Devices:='['+DeviceName+']';
    ThisRestore.Action:=RestoreType;
    ThisRestore.SQLRestore(FServer);
    end;
      

  2.   

    必须先安装SQL Server企业管理器.
    1) Choose project, Import typelibrary.
    2) Look for "Microsoft SQLNamespace Object Library" in the list.
      

  3.   

    晕,SQL都好好的,以前也是一样的,只是在D里面长不到这个东西~~
      

  4.   

    先选择project,然后Import typelibrary导入Microsoft SQLNamespace Object Library类型库就可以了。