既然用,那么ODBC中设置的用户DSN或系统DSN就是对应的别名.
只要手工设置好ODBC或者在程序中即可.
客户端和服务器的安装没有什么不同,唯一的差别就是:
在服务器端设置ODBC时, 服务器名可以用 . 或者 (local) 来表示
当然, 做安装盘时BDE是不可少的,但可以为其BDE减肥, 减肥方法请搜索或
另提问题:
下面先给你一段程序设置ODBC DSN的代码:
Function CreateSQLServerDsn(const FDSN,FServer,FUser:String):Integer;
implementation
Function CreateSQLServerDsn(const FDSN,FServer,FUser:String):Integer;
var
RegisterTemp:TRegistry;
s : string;
begin
RegisterTemp:=TRegistry.Create;
with RegisterTemp do
begin
RootKey:=HKEY_LOCAL_MACHINE;
//首先判断此DSN是否已经存在,如在,则不用继续下去
if OpenKey('Software/ODBC/ODBC.INI/'+FDSN,False) then
begin
CloseKey;
Result:=0;
Free;
exit;
end;
CloseKey;
//判断SQL Server的驱动程序是否已经安装
If OpenKey('Software/ODBC/ODBCINST.INI/ODBC Drivers',False) then
begin
s:=ReadString('SQL Server');
if UpperCase(S)<>'INSTALLED' then
begin
CloseKey;
Result:=2;
Free;
exit;
end;
end
else
begin
CloseKey;
Result:=3;
Free;
exit;
end;
CloseKey;
//寻找SQL Server的驱动程序路径
If OpenKey('Software/ODBC/ODBCINST.INI/SQL Server',False) then
begin
s:=ReadString('Driver');
if S='' then
begin
CloseKey;
Result:=2;
Free;
exit;
end;
end
else
begin
CloseKey;
Result:=2;
Free;
exit;
end;
CloseKey;
//注册一个DSN名称
If OpenKey('Software/ODBC/ODBC.INI/ODBC Data Sources',True) then
WriteString(FDSN,'SQL Server')
else
begin
CloseKey;
Result:=1;
Free;
exit;
end;
CloseKey;
if OpenKey('Software/ODBC/ODBC.INI/'+FDSN,True) then
begin
WriteString('Driver',S);
WriteString('LastUser',FUser);
WriteString('Server',FServer);
Result:=5;
end
else
begin
CloseKey;
Result:=1;
Free;
exit;
end;
CloseKey;
Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
i :=CreateSQLServerDsn(trim(Edit1.Text), trim(Edit3.Text),trim(Edit4.Text));
if i= 5 then ShowMessage('成功');
if i= 0 then ShowMessage('失败:'+IntToStr(i));
end;