?? unit1.pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls,Inifiles, Buttons;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
btncreatedb: TBitBtn;
procedure btncreatedbClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btncreatedbClick(Sender: TObject);
Var
strcon,server,user,psw,dbpath,Restrostr:string;
MyInifile:Tinifile;
begin
MyInifile:=Tinifile.Create(ExtractFilePath(Application.ExeName)+'db_login.ini');
server:=MyInifile.ReadString('sysdb','hostname','localhost');
user:=MyInifile.ReadString('sysdb','UserName','sa');
psw:=MyInifile.ReadString('sysdb','PassWord','1234');
strcon:='Provider=SQLOLEDB.1;Password='+trim(psw)+ ';Persist Security Info=True;User ID='+trim(user) + ';Initial Catalog=;Data Source='+trim(server);
ADOConnection1.close;
ADOConnection1.ConnectionString:=strcon;
try
ADOConnection1.Open;
//MessageBox(0,'數據庫連接成功','提示',MB_OK+MB_iconinformation);
except
begin
MessageBox(0,'數據庫連接失敗','警告',MB_OK+MB_iconwarning);
exit;
end;
end;
//----------------創建數據庫
try
dbpath:=ExtractFilePath(Application.ExeName);
//RestorStr := 'restore DATABASE children from disk= ''' + trim(dbpath) + ''' ';
Restrostr:='begin';
ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+'begin';
Restrostr:='exec sp_attach_db @dbname = N' + '''' +'children'+ '''' +',';
ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+Restrostr;
//@filename1 = N'F:\msdeCon\data\corrosion_Data.mdf',
Restrostr:='@filename1 = N'+''''+ dbpath+'data\children_Data.mdf'+'''' +',';
ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+Restrostr;
Restrostr:='@filename2 = N'+''''+ dbpath+'data\children_log.ldf'+'''';
ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+Restrostr;
ADOQuery1.SQL.Text:=ADOQuery1.SQL.Text+'end';
ADOQuery1.ExecSQL;
MessageBox(0,'數據庫創建成功','提示',MB_OK+MB_iconinformation);
close;
except
begin
MessageBox(0,'數據庫創建失敗','警告',MB_OK+MB_iconwarning);
exit;
end;
end; //try
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -