编程增加ORACLE别名!(wzs)(200分)

  • 主题发起人 主题发起人 wzs
  • 开始时间 开始时间
W

wzs

Unregistered / Unconfirmed
GUEST, unregistred user!
tnsname.ora ?!
 
想达到什么效果?只是在文件里加几行字符?
需要测试你加的别名是否能成功连结吗?这就比较难了...
hehe,不是有net easy config嘛...
 
使用三个EDIT
分别对应
HOST
PORT
SID
写以下语句
到TNSNAME。ORA 中即可

TCPEXAMPLE.WORLD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = edit1.text)(PORT = edit1.text))
(CONNECT_DATA = (SID = edit1.text))
)
 
arm is right

补充一点:
从注册表中获得tnsname.ora文件的路径(HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/network OR NET80),
打开后增加

测试你加的别名是否能成功连结可用一db控件( 加try)
 
oracle 7.x for win98 是不行的 ,for nt 还没试过 ,谁有玩过????!!!!
具体情况如何!!!!!!
 
wzs:如果还想接着讨论请定期提前自己的帖子,如果不想继续讨论请结束帖子。
 
unit alias;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Registry, filectrl;

type
TForm1 = class(TForm)
alias: TEdit;
host: TEdit;
port: TEdit;
sid: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
ls_reg_path: string;
path: string;
filename: string;
fid: TextFile;
ss:string;
begin
path := '';

ls_reg_path := '/Software/ORACLE';
with TRegistry.Create do
begin
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(ls_reg_path,false) then
begin
path:=ReadString('NET80');
if path = '' then
path:=ReadString('NETWORK');
end;
finally
CloseKey ;
free;
end;
end;
if path = '' then
begin
application.MessageBox('请确认已安装Oracle7.0以上数据库','错误',MB_OK);
abort;
end;
path := path + '/ADMIN';
filename := path + '/Tnsnames.ora';

assignfile(fid,filename);
ss := #13#10 + alias.Text + '.WORLD = ' + #13#10;
ss := ss + ' (DESCRIPTION = ' + #13#10;
ss := ss + ' (ADDRESS = (PROTOCOL = TCP)(HOST = ' +host.text+')(PORT = '+port.text+')) ' + #13#10;
ss := ss + ' (CONNECT_DATA = (SID = ' + sid.Text + ')) ' + #13#10;
ss := ss + ' ) ' + #13#10;

append(fid);
writeln(fid,ss);
Flush(fid);
CloseFile(fid);

end;

end.
 
同意pqx
我也是刚刚试过,可以的,我联的是linux上的oracle 8.0.5
 
后退
顶部