分发软件时,如何直接把做好Sql 数据库附加到别人机子上Sql Server!!!!
以免还要在企业管理器重新附加....
以免还要在企业管理器重新附加....
解决方案 »
- delphi中怎样能输出类的类型信息?
- treeview調用問題?
- 用的是Delphi6自带的DBGrid控件,我把它的dgMultiSelect...
- 动态连接库中的入口\出口函数你测试过没有?
- 请问大家,Delphi7 和 Delphi6 有什么区别?
- 如何在delphi中编写CD播放器程序?
- delphi+mysql 问题,高手请进
- 哪里有delphi6 service pack 1下载啊?
- 我要用delphi开发一个串口通信的实现的测试小程序。怎么办。MSCOMM控件和 SPCOMM控件又是如何获取的,谢谢
- 奇怪的系统问题
- delphi与access或sql数据库连接语句
- 怎样使得QuickRep只能预览不能打印!小弟在线求助!送分!
//被老板看见就惨了(看完赶紧删了)
unit UnitMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DB, ADODB,Registry,comobj,activex,shlobj, jpeg,
ExtCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Label4: TLabel;
MaskEdit1: TMaskEdit;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOStoredProc1: TADOStoredProc;
Image1: TImage;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button3Click(Sender: TObject);
private
function copyDataFile:boolean;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
success:boolean;
implementation{$R *.dfm}procedure CreateLinkFileForWygl;
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
StartupFilename : String;
LinkFilename : WideString;
begin
StartupFilename := 'http://localhost/wyglWQB/default.aspx';
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定notepad.exe所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,
CSIDL_DESKTOPDIRECTORY,
PIDL);//获得桌面的Itemidlist
SHGetPathFromIDList(PIDL,
StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + '\思睿物业管理系统.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;
procedure TForm1.Button1Click(Sender: TObject);
var currentPath:string;
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
//判断是否安装mssqlserver2000
Reg.RootKey := HKEY_LOCAL_MACHINE;
if not reg.openkeyReadOnly('\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion') then begin
showmessage('MS SQL Server 2000不存在!请先安装MS SQL Server 2000。');
exit;
end;
if not (reg.ReadString('CurrentVersion')>'8') then begin
showmessage('MS SQL Server 版本太低!请先安装MS SQL Server 2000。');
exit;
end;
finally
reg.CloseKey;
reg.Free;
end;
if not copyDataFile then begin//拷贝文件失败就退出安装
application.MessageBox(pchar('数据库安装失败!'),pchar('错误'),mb_iconerror);
exit;
end;
self.ADOConnection1.ConnectionString:= 'Provider=SQLOLEDB.1;Persist Security Info=False;Password='+maskedit1.text+';User ID='+self.Edit1.Text+';Data Source=localhost';
currentPath:=extractFilePath(application.ExeName);
with adoquery1 do
begin
SQL.Clear ;
SQL.add('sp_attach_db @dbname=N'+''+'''wyglWQB'''+''+' , ');
SQL.add('@filename1=N'+''''+'c:\wyglData\wyglWQB_Data.MDF'+''''+' , ');
sql.add('@filename2=N'+''''+'c:\wyglData\wyglWQB_Log.LDF''')
end;
try
try
adoquery1.ExecSQL;
showmessage('数据库安装成功!');
CreateLinkFileForWygl;
showmessage('物业管理系统安装完毕!请运行桌面上的“思睿物业管理系统”。');
success:=true;
close;
except
on E: Exception do application.MessageBox(pchar('操作失败!失败原因如下:'+#13#10+e.Message),pchar('错误'),mb_iconError);
end;
finally
adoconnection1.Close;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if success then begin
canClose:=true;
exit;
end;
if application.MessageBox(pchar('退出安装你将不能正常使用物业管理软件!'#13#10'你确定要退出吗?'),pchar('请确定'),MB_YESNO|mb_iconinformation)=IDYES then
canClose:=true
else
canClose:=false;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
CreateLinkFileForWygl;
end;function TForm1.copyDataFile: boolean;
var fullPath:string;
begin
if not DirectoryExists('c:\wyglData') then
if not CreateDir('C:\wyglData') then begin
application.MessageBox(pchar('不能创建文件夹 c:\wyglData'),pchar('数据库安装失败'),mb_iconerror);
result:=false;
exit;
end;
fullPath:=extractFilePath(application.ExeName);
if not copyfile(pchar(fullPath+'wyglWQB_data.mdf'),pchar('c:\wyglData\wyglWQB_data.mdf'),true) then begin
application.MessageBox(pchar('文件 c:\wyglData\wyglWQB_Data.mdf已经存在!'),pchar('错误失败'),mb_iconerror);
result:=false;
end else begin
copyfile(pchar(fullPath+'wyglWQB_log.ldf'),pchar('c:\wyglData\wyglWQB_Log.ldf'),false);
FileSetAttr('c:\wyglData\wyglWQB_data.mdf',32);//改变文件属性为可读写
FileSetAttr('c:\wyglData\wyglWQB_log.ldf',32);
result:=true;
end;
end;end.
这样就把数据库附加进去了