编程可以建立ODBC,但其配置“SQL SERVER验证登陆ID的真伪”时,如何设置使其选择第二项“使用用户输入登陆ID和密码的SQL SERVER验证”,并在其下的“登陆ID”和“密码”中输入对应值呢?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var  wreg: tregistry;
         tmpPath: array[0..255]of char;
         sysPath: string;
         tmpdbpath:string;
         tpath: string;
    begin
      getsystemdirectory(tmppath,255);
      {getsystemdirectory函数能取得Windows系统目录(System目录)的完整路径名}
      syspath:=strpas(tmppath);
      {strpas()--将null结尾字符串转成一个pascal格式字符串}
      tpath:=extractfilepath(application.ExeName);
      tmpdbpath:=tpath+'test.mdb';//指定连接数据库的路径
      if not fileexists(tmpdbpath) then
      begin
        messagebox(handle,pchar('找不到存储路径'+tmpdbpath+'的数据文件'),
                   promsg, mb_ok+mb_iconwarning);
        exit;
      end;  //建立一个Registry实例
      wreg:=tregistry.Create;
      //-==注册ODBC==-
      with wreg do
      begin                  
        rootkey:=hkey_local_machine;
        if openkey('software\odbc\odbc.ini\odbc data sources',true) then
          writestring('regtest','microsoft access driver (*.mdb)')
        else
        begin
          application.MessageBox('ODBC初始化错误',promsg,
              mb_ok+mb_iconexclamation);
          exit;
        end;
        closekey;    //写入DSN配置信息
        if openkey('software\odbc\odbc.ini\regtest',true) then
        begin
          writestring('dbq',tmpdbpath);//数据库目录
          writestring('description','Pasc数据源'); //数据源描述
          writestring('driver',syspath+'\odbcjt32.dll'); //驱动程序dll文件
          writeinteger('driverid',25);
          writestring('fil','MS Access;');
          writeinteger('safetransactions',0);  //支持的事务操作树目
          writestring('uid','');               //用户名称
        end
        else
        begin
          application.MessageBox('ODBC初始化错误',promsg,
              mb_ok+mb_iconexclamation);
          exit;
        end;
        closekey;    if openkey('software\odbc\odbc.ini\regtest\engines\jet',true) then
        begin
          writestring('implicitcommitsync','yes');
          writeinteger('maxbuffersize',2048);//缓冲区大小
          writeinteger('threads',3);         //支持的线程数目
          writeinteger('pagetimeout',10);    //页超时
          writestring('usercommitsync','yes'); 
        end
        else
        begin
          application.MessageBox('ODBC初始化错误',promsg,
              mb_ok+mb_iconexclamation);
          exit;
        end;
        closekey;    free;
      end;  application.MessageBox('用户信息注册成功',promsg,
              mb_ok+mb_iconinformation);
    end;
    //以上是编程建立odbc,就是向注册表内写东西
      

  2.   

    楼上的是ACCESS数据库,有SQL SERVER的例子吗,主要是怎么在注册表中设置“登陆ID”和“密码”的值!
      

  3.   

    //////如何用代码自动建ODBC以下是在程序中动态创建ODBC的DSN数据源代码: 
    procedure TCreateODBCDSNfrm.CreateDSNBtnClick(Sender: TObject); 
    var 
      registerTemp : TRegistry; 
      bData : array[ 0..0 ] of byte; 
    begin 
      registerTemp := TRegistry.Create; 
      //建立一个Registry实例 
      with registerTemp do 
           begin 
          RootKey:=HKEY_LOCAL_MACHINE; 
          //设置根键值为HKEY_LOCAL_MACHINE 
          //找到Software\ODBC\ODBC.INI\ODBC Data Sources 
          if OpenKey('Software\ODBC\ODBC.INI 
          \ODBC Data Sources',True) then 
         begin //注册一个DSN名称 
         WriteString( 'MyAccess', 'Microsoft 
          Access Driver (*.mdb)' ); 
               end 
             else 
               begin//创建键值失败 
         memo1.lines.add('增加ODBC数据源失败'); 
         exit; 
          end; 
          CloseKey; 
    //找到或创建Software\ODBC\ODBC.INI 
     \MyAccess,写入DSN配置信息 
          if OpenKey('Software\ODBC\ODBC.INI 
          \MyAccess',True) then 
         begin 
         WriteString( 'DBQ', 'C:\inetpub\wwwroot 
         \test.mdb' );//数据库目录,连接您的数据库 
         WriteString( 'Description', 
         '我的新数据源' );//数据源描述 
         WriteString( 'Driver', 'C:\PWIN98\SYSTEM\ 
         odbcjt32.dll' );//驱动程序DLL文件 
         WriteInteger( 'DriverId', 25 ); 
         //驱动程序标识 
         WriteString( 'FIL', 'Ms Access;' ); 
         //Filter依据 
         WriteInteger( 'SafeTransaction', 0 ); 
         //支持的事务操作数目 
         WriteString( 'UID', '' );//用户名称 
         bData[0] := 0; 
         WriteBinaryData( 'Exclusive', bData, 1 ); 
         //非独占方式 
         WriteBinaryData( 'ReadOnly', bData, 1 ); 
         //非只读方式 
               end 
             else//创建键值失败 
               begin 
         memo1.lines.add('增加ODBC数据源失败'); 
         exit; 
          end; 
          CloseKey; 
    //找到或创建Software\ODBC\ODBC.INI 
    \MyAccess\Engines\Jet 
        //写入DSN数据库引擎配置信息 
          if OpenKey('Software\ODBC\ODBC.INI 
         \MyAccess\Engines\Jet',True) then 
         begin 
         WriteString( 'ImplicitCommitSync', 'Yes' ); 
         WriteInteger( 'MaxBufferSize', 512 );//缓冲区大小 
         WriteInteger( 'PageTimeout', 10 );//页超时 
         WriteInteger( 'Threads', 3 );//支持的线程数目 
         WriteString( 'UserCommitSync', 'Yes' ); 
               end 
             else//创建键值失败 
               begin 
         memo1.lines.add('增加ODBC数据源失败'); 
         exit; 
          end; 
          CloseKey; 
             memo1.lines.add('增加新ODBC数据源成功'); 
          Free; 
           end; 
    end;
      

  4.   

    楼上:我要的是建立SQL SERVER的,你的是ACCESS的!
      

  5.   

    procedure TMainFrm.RegODBC;
    var wReg: TRegistry;
        tmpdbPath: string;
        SysPath: array [0..255] of char;
    begin
      getsystemdirectory(SysPath,255);
      {getsystemdirectory函数能取得Windows系统目录(System目录)的完整路径名}  wreg:=tregistry.Create;
      wreg.RootKey:=hkey_users;
      if wreg.OpenKey('S-1-5-21-776561741-789336058-1343024091-500\Software\odbc\odbc.ini\ExamSys',
                      true) then
      begin
         wreg.WriteString('Database','ExamSys');
         wreg.WriteString('Description','考试系统');
         wreg.WriteString('Driver',SysPath+'SQLSRV32.dll');
         wreg.WriteString('Server','SPEEDZY');  //SQLSERVER服务器名
         wreg.WriteString('Trusted_Connection','Yes');
      end
      else
      begin
        application.MessageBox('ODBC初始化错误,本程序即将关闭。'+#13#10+
        '关闭后请先检查ODBC是否有错误或未安装,先排除错误或安装后再运行本程序。',
                               '错误', mb_ok+mb_iconerror);
        application.Terminate ;
      end;
      wreg.CloseKey;  if wreg.OpenKey('S-1-5-21-776561741-789336058-1343024091-500\Software\odbc\odbc.ini\ODBC Data Sources',
                      false) then
        wreg.WriteString('ExamSys','SQL Server')
      else
      begin
        application.MessageBox('ODBC初始化错误,本程序即将关闭。'+#13#10+
        '关闭后请先检查ODBC是否有错误或未安装,先排除错误或安装后再运行本程序。',
                               '错误', mb_ok+mb_iconerror);
        application.Terminate ;
      end;
      wreg.CloseKey;        //
    end;
      

  6.   

    其实自己用管理工具中的ODBC数据源建一个sql server的,再看看注册表就清楚了
      

  7.   

    楼上的,你的代码也不能满足我的要求,也只能建立“使用网络登陆ID的WINDOWS NT”而不是我需要的第二项,两者在注册表中看不出差别!
      

  8.   

    我要的是建立SQL SERVER的,你的是ACCESS的!你不知道该一下里面的参数啊?非的要把饭喂到你嘴里你才吃吗?
      

  9.   

    SQL SERVER验证登陆ID的真伪”“使用用户输入登陆ID和密码的SQL SERVER验证”,是在sql server 服务器中设置,不是在客户端设置
      

  10.   

    zs_xj(胖子) :我就是想在作安装程序时,直接修改.
    princesd(中原) :能说说是哪个参数呢,我看不出来!
      

  11.   

    我下载WISE看看好像可以满足我的大部分功能,大家有没有关于WISE的教程呀!
      

  12.   

    求Wise Installation System教程!