我想用ADOConnection连接SQL数据库,连接字符串的相关参数保存在配置文件setup.ini文件中。当点击运行时,就出现“ADO连接时“[DBNETLIB][ConnectionOpen (Connect()).]SQL Server 不存在或拒绝访问”,请各位大哥帮忙看一下问题出在哪里,小弟不胜感激!
程序代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit2, Inifiles, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label2: TLabel;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
server,base:String;
setupfile:Tinifile;
begin
setupfile:=TinifilE.create(extractfiledir(application.ExeName)+'\setup.ini');
server:=setupfile.Readstring('system','servername','');
base:=setupfile.Readstring('system','database','');
try
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;'
+'Integrated Security=SSPI;Persist Security Info=false;'
+'Initial Catalog='+server+';Data Source='+base;
ADOConnection1.Open;
if ADOConnection1.Connected then
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from user_table where user_name='''+edit1.text+'''');
ADOQuery1.Open;
if ADOQuery1.Eof then
begin
SHOWMESSAGE('不得');
end
else
begin
Form2.Show;
Form1.Hide;
end;
except
application.MessageBox('数据库连接失败,请确认无误后重试!','提示:')
end;
end;
end.