如何在客户端让用户选择SQL Server服务器的文件夹?

sywxy 2007-07-02 09:59:51
就像企业管理器中备份/还原数据库一样,选择备份设备位置,操作者可以选择sql server服务器里的文件夹。
...全文
665 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
sywxy 2007-07-08
  • 打赏
  • 举报
回复
返回服务器的文件夹已经完成了,但是如何返回当前文件夹中的文件呢?这又是一个问题。
如果使用exec master..xp_cmdshell 'dir "c:\windows"' 感觉不是一个好的办法。
Hank 2007-07-03
  • 打赏
  • 举报
回复
不建议这么做,虽然有很多种方法,这最主要的是考虑安全性。

数据库的维护就是要到数据库服务器上去做,如果客户端可以做就太危险了尤其是恢复操作。
lifengguo 2007-07-03
  • 打赏
  • 举报
回复
SQL DMO组件获取服务器列表
hongqi162 2007-07-02
  • 打赏
  • 举报
回复
http://blog.csdn.net/lw549/archive/2005/04/05/337299.aspx
sywxy 2007-07-02
  • 打赏
  • 举报
回复
得到了SQLNS_TLB.pas和SQLDMO_TLB.pas ,但是SQLNS.pas和SQLDMO.pas 如何得到呢?
sywxy 2007-07-02
  • 打赏
  • 举报
回复
好,学习学习。
ron_xin 2007-07-02
  • 打赏
  • 举报
回复
顶`~~学习`~
hongqi162 2007-07-02
  • 打赏
  • 举报
回复
sqldemo中提供EnumDirectories
hongqi162 2007-07-02
  • 打赏
  • 举报
回复
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;
sywxy 2007-07-02
  • 打赏
  • 举报
回复
这并不是一个好办法。服务器也不能随便共享。
我是在做一个多账套维护系统,新建账套时需要由操作者指定在服务器的哪个文件夹上新建数据库。
brightyang 2007-07-02
  • 打赏
  • 举报
回复
把服务器端的文件共享
qgcsoft 2007-07-02
  • 打赏
  • 举报
回复
建议如下:
1\首先读取SQL SERVER数据库中所有数据名称
2\把数据库名称读入列表框中;
3\然后利用SQL语句来对相应的数据库操作(如备份/还原等)

具体SQL怎么样写,SQL SERVER帮助里面写的比较详细的.
hongqi162 2007-07-02
  • 打赏
  • 举报
回复
是的,要不你怎么形成服务器的目录结构
sywxy 2007-07-02
  • 打赏
  • 举报
回复
如果操作者操作服务器的文件夹是不是还需要自己设计一个窗口然后再做一个树?

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧