主题:delphi连接数据库ini读取问题
我做了个登陆界面,想运行程序时系统按照ini读取连接参数,ini放在d盘,由于是菜鸟,一直没有调试出来,下面是源代码,望前辈赐教:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, IniFiles,XPMan;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Edit1: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
XPManifest1: TXPManifest;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
IniFile:TIniFile;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var
DataSource,InitialCatalog,UserId,Password : string;
//Filename:=ExtractFilePath(Paramstr(0))+’d:\connection.ini’;
IniFile:=TInifile.Create(’d:\connection.ini’);
begin
DataSource:=INI.Readstring('connection','Data Source','');
InitialCatalog:=INI.Readstring('connection','Initial Catalog','');
UserId:=INI.Readstring('connection','user id','');
Password:=INI.Readstring('connection','password','');
ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Persist Security Info=true;User ;password='+Password+';Initial Catalog='+InitialCatalog+';data source='+DataSource;
ADOConnection1.Connected := True;
ADOConnection1.loginprompt :=false;
ini.Free;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, IniFiles,XPMan;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Edit1: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
XPManifest1: TXPManifest;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
IniFile:TIniFile;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
Var
DataSource,InitialCatalog,UserId,Password : string;
//Filename:=ExtractFilePath(Paramstr(0))+’d:\connection.ini’;
IniFile:=TInifile.Create(’d:\connection.ini’);
begin
DataSource:=INI.Readstring('connection','Data Source','');
InitialCatalog:=INI.Readstring('connection','Initial Catalog','');
UserId:=INI.Readstring('connection','user id','');
Password:=INI.Readstring('connection','password','');
ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Persist Security Info=true;User ;password='+Password+';Initial Catalog='+InitialCatalog+';data source='+DataSource;
ADOConnection1.Connected := True;
ADOConnection1.loginprompt :=false;
ini.Free;
end;
end.