我在窗体创建的时候,来连接数据库。我是用ado的。代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
SYSINI: TINIFile;
filename:string;
begin
ADOConnection1.Connected := False;
if ADOConnection1.Connected = False then
begin
try
filename:=extractfilepath(paramstr(0))+'\ini\server.ini';
sysini:=tinifile.Create(filename);
UserName := SYSINI.ReadString('Database', 'UserName', '');
InitDB := SYSINI.ReadString('Database', 'InitDB', '');
Password := SYSINI.ReadString('Database', 'Password', '');
finally
SYSINI.Free;
end;
end;
ADOConnection1.ConnectionString :=
'Provider=SQLOLEDB.1;'
+'Password='+Password+';'
+'Persist Security Info=True;'
+'User ID='+UserName+';'
+'Initial Catalog='+initdb+';'
+'Data Source='+ServerName+';'
+'Use Procedure for Prepare=1;'
+'Auto Translate=True;'
+'Packet Size=4096;'
+'Workstation ID='+ServerName+';'
+'Use Encryption for Data=False;'
+'Tag with column collation when possible=False' ;
try
ADOConnection1.Connected := True;
except
showmessage('CONNECTION IS WRONG cant found the sql server!');
application.Terminate ;
end;end;procedure TForm1.Button2Click(Sender: TObject);
begin
FORM1.ADOQuery1.Connection:=form1.ADOConnection1;
form1.ADOQuery1.Close ;
form1.ADOQuery1.SQL.Clear ;
form1.ADOQuery1.SQL.Add('select * from PYJ');
form1.ADOQuery1.Open;
form1.DataSource1.DataSet:=form1.ADOQuery1;
form1.DBGrid1.DataSource:=form1.DataSource1;
end;
ini文件如下:
[Database]
ServerName=192.168.0.1
InitDB=LEW
UserName=GUEST_USER
Password=WXYJ
我的问题是,我在本机,使用一切正常,但是我把程序copy到别的电脑上面就 不可以拉。
这是为什么呢?在本机的时候,安装数据库的时候,我是用sa验证,录入了sa的密码,然后我在数据库里面建立了一个用户,GUEST_USER,密码是:WXYJ,我是想在写程序的时候,用GUEST_USER来验证的。在别的电脑上面使用,提示。showmessage('CONNECTION IS WRONG cant found the sql server!');,就是连接数据库不能通过。
procedure TForm1.FormCreate(Sender: TObject);
var
SYSINI: TINIFile;
filename:string;
begin
ADOConnection1.Connected := False;
if ADOConnection1.Connected = False then
begin
try
filename:=extractfilepath(paramstr(0))+'\ini\server.ini';
sysini:=tinifile.Create(filename);
UserName := SYSINI.ReadString('Database', 'UserName', '');
InitDB := SYSINI.ReadString('Database', 'InitDB', '');
Password := SYSINI.ReadString('Database', 'Password', '');
finally
SYSINI.Free;
end;
end;
ADOConnection1.ConnectionString :=
'Provider=SQLOLEDB.1;'
+'Password='+Password+';'
+'Persist Security Info=True;'
+'User ID='+UserName+';'
+'Initial Catalog='+initdb+';'
+'Data Source='+ServerName+';'
+'Use Procedure for Prepare=1;'
+'Auto Translate=True;'
+'Packet Size=4096;'
+'Workstation ID='+ServerName+';'
+'Use Encryption for Data=False;'
+'Tag with column collation when possible=False' ;
try
ADOConnection1.Connected := True;
except
showmessage('CONNECTION IS WRONG cant found the sql server!');
application.Terminate ;
end;end;procedure TForm1.Button2Click(Sender: TObject);
begin
FORM1.ADOQuery1.Connection:=form1.ADOConnection1;
form1.ADOQuery1.Close ;
form1.ADOQuery1.SQL.Clear ;
form1.ADOQuery1.SQL.Add('select * from PYJ');
form1.ADOQuery1.Open;
form1.DataSource1.DataSet:=form1.ADOQuery1;
form1.DBGrid1.DataSource:=form1.DataSource1;
end;
ini文件如下:
[Database]
ServerName=192.168.0.1
InitDB=LEW
UserName=GUEST_USER
Password=WXYJ
我的问题是,我在本机,使用一切正常,但是我把程序copy到别的电脑上面就 不可以拉。
这是为什么呢?在本机的时候,安装数据库的时候,我是用sa验证,录入了sa的密码,然后我在数据库里面建立了一个用户,GUEST_USER,密码是:WXYJ,我是想在写程序的时候,用GUEST_USER来验证的。在别的电脑上面使用,提示。showmessage('CONNECTION IS WRONG cant found the sql server!');,就是连接数据库不能通过。
解决方案 »
- 求助DBImage之类的第三方控件
- 谁帮我介绍一个牛B一点的delphi群
- (再线等待)急! 关于文件读取及其类型转换问题
- 做个小调查[来者有分]:你们在开发时用数据感知控件(比如TDBEdit等)吗?
- *** 怎么判断TADOQuery的记录是否被改变?**************
- 欢迎MIDAS高手进入……
- Delphi7Delphi7和Delphi6有什么区别?
- 不知道谁能提供一个控件。100分送.~~~~~~~~~~oooooo~~~~~~~~~
- 请教:Delphi中TTreeView中的项目序列如何调整??急用 + 高分
- 写个ActiveX不知道在网页里怎让传参数
- 这个错误老出现!大家说说怎么解决?
if Edt_Machine.Text ='' then
begin
messagebox(handle,'服务器名不能为空,请重新输入!','提醒!!',mb_iconinformation);
Edt_Machine.SetFocus;
exit;
end;
if rbt_db.Checked =true then
begin
Dm.adc_connect.Close;
Dm.adc_connect.ConnectionString:='';
Dm.adc_connect.ConnectionString:=format(ora_constring,[Edt_Password.Text,
Edt_Username.Text,
Edt_Machine.text]);
try
Dm.adc_connect.Connected :=true;
messagebox(handle,'数据库连接成功!','注意',mb_iconinformation);
frmconnect.Hide;
frmselect.show;
except
messagebox(handle,'数据库连接失败!','注意',mb_iconinformation);
Dm.adc_connect.Close;
end;
end;
加SA用户,设置登录密码为GEST_USER