诸位大侠:   我想在客户的机器上创建sql 数据库别名( 单机环境)参数如下:===============================================================================================
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=lz;Data Source=.;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=CWB;Use Encryption for Data=False;Tag with column collation when possible=False
=============================================================================================== 以前我用语句创建access 数据库别名的语句如下:(现在创建sql 数据别名也想参照这个格式):===============================================================GetWindowsDirectory(buffer, SizeOf(buffer));
r:=tregistry.create;
with r do
begin
rootkey:=hkey_local_machine;
if openkey('software\odbc\odbc.ini\odbc data sources',true) then
begin
writestring('lz','Microsoft Access Driver (*.mdb)');
end;
closekey;
if openkey('software\odbc\odbc.ini\ggmt',true) then
begin
writestring('DBQ',strAppPath+'data\dir');
writestring('DRIVER',buffer+'\system\odbcjt32.dll');
WriteInteger('DriverId',25);
writestring('FIL','ms access');
WriteInteger('SafeTransactions',0);
end;
if openkey('engines\jet',true) then
begin
writestring('ImplicitCommitSync','');
WriteInteger('MaxBufferSize',2048);
WriteInteger('PageTimeout',5);
WriteInteger('Threads',3);
writestring('UserCommitSync','yes');
end;
closekey;
free;
end;       ==========================================
大侠们,谢了

解决方案 »

  1.   

    先建立一个ODBC源,查看其配置属性,然后找你上面步骤做,应该可以。
    既然是sqlserver,何必用别名呢,直接用OLE连接不简单吗?
      

  2.   

    function GetConnString(DBKind,DBName: String): String;  // 取数据库连接串
    var
      MachineName: string;
    begin
      if DBKind='ACCESS' then  // ACCESS 库
        Result := 'Provider=Microsoft.JET.OLEDB.4.0;'+
                  'Persist Security Info=True;Mode=Share Deny None;'+
                  'Data Source='+_DIR_APP+DBName+'.mdb;'+
                  'User ID=Admin; Jet OLEDB:Database Password='+_ACCESS_PSW
      else begin
        if Copy(_IP_ADDRESS,1,3) = '127' then
          GetNameByIPAddr(_IP_ADDRESS,MachineName)  // 转换为机器名访问SQL SERVER 服务器
        else
          MachineName := _IP_ADDRESS;  // 由于单机下访问 SQL SERVER 服务器失败,故做转换
        Result := 'Provider=SQLOLEDB.1;'+
                  'Persist Security Info=True;' +
                  'Initial Catalog=' + DBName + ';'+
                  'Data Source=' + MachineName + ';'+
                  'User ID=' + _LOGIN_USER + '; PASSWORD=' + _LOGIN_PSW
      end;
    end;function GetNameByIPAddr(IPAddr: string;var MacName: string): boolean;
    var
      SockAddrIn: TSockAddrIn;
      HostEnt: PHostEnt;
      WSAData: TWSAData;
    begin
      Result := False;
      if IpAddr = '' then exit;
      try
        WSAStartup(2, WSAData);
        SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
        HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
        if HostEnt <> nil then MacName := StrPas(Hostent^.h_name);
        Result := True;
      finally
        WSACleanup;
      end;
    end;
      

  3.   

    客户环境:sql数据库+单机,没有sql server服务器 ,很小的程序
      

  4.   

    GetWindowsDirectory(buffer, SizeOf(buffer));
    r:=tregistry.create;
    with r do
    begin
    rootkey:=hkey_local_machine;
    if openkey('software\odbc\odbc.ini\odbc data sources',true) then
    begin
    writestring('lz','Microsoft Access Driver (*.mdb)');
    end;
    closekey;
    if openkey('software\odbc\odbc.ini\CWB',true) then
    begin
    writestring('DataBase','lz');
    writestring('DRIVER','C:\WINDOWS\system32\sqlsrv32.dll');
    WriteInteger('LastUser','sa');
    writestring('Server','(local)');end;closekey;
    free;
    end;     
    try it again.