你可看看下面的代码。
VAR
registerTemp : TRegistry;
PathName: array[0..MAX_PATH] of char;
{$R *.RES}
begin
//**************************************
// 創建ODBC數据源--MRP // 2002/3/29
// 編程: 丁繼東 //
//**************************************
{GetSystemDirectory(PathName, MAX_PATH);
copydir(ExtractFilePath(Application.EXEName)+'updbpl',strpas(PathName));}
GetTempPath(MAX_PATH, @PathName);
registerTemp := TRegistry.Create;
//建立一個Registry實例
with registerTempdo
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
//注冊一個DNS名稱
WriteString( 'MRP', 'SQL Server' );
end
else
begin
//創建鍵值失敗
Application.messagebox('ODBC數据源創建失敗!!!'#10#13'請与丁繼東聯絡.','ODBC錯誤',0);
Application.Terminate;
//exit;
end;
CloseKey;
//找到或創建Software/ODBC/ODBC.INI/MyTest,加入DSN配置信息
if OpenKey('Software/ODBC/ODBC.INI/MRP',True) then
begin
WriteString( 'DataBase', 'MRPII' );//數据庫名
WriteString( 'Driver', string(PathName)+'sqlsrv32.dll' );//所需程序DLL文件
WriteString( 'LastUser', 'SA' );//用戶名
if not ValueExists('Server') then
WriteString( 'Server', 'KHSQL' );//服務器名稱
end
else
//創建鍵值失敗
begin
Application.messagebox('ODBC數据源創建失敗!!!'#10#13'請与丁繼東聯絡.','ODBC錯誤',0);
//showmessage('ODBC數据源創建失敗!!!'#10#13'請与丁繼東聯絡.');
Application.Terminate;
//exit;
end;
CloseKey;
if OpenKey('Software/Borland/Database Engine/Settings/System/INIT',false) then
begin
WriteString('SQLQRYMODE','SERVER');
WriteString('SYSFLAGS','0');
WriteString('MTS POOLING','TRUE');
WriteString('LOW MEMORY USAGE LIMIT','32');
WriteString('MAXBUFSIZE','16384');
WriteString('MAXFILEHANDLES','120');
WriteString('SHAREDMEMSIZE','16384');
WriteString('MEMSIZE','128');
WriteString('MINBUFSIZE','8192');
end;
CloseKey;
if OpenKey('Software/Borland/Database Engine/Settings/DRIVERS/SQL Server/INIT',false) then
begin
WriteString('DRIVER FLAGS','0');
WriteString('TYPE','SERVER');
end;
CloseKey;
if OpenKey('Software/Borland/Database Engine/Settings/DRIVERS/SQL Server/DB OPEN',false) then
begin
WriteString('BLOB SIZE','32');
WriteString('BLOB TO CACHE','64');
WriteString('ENABLE BCD','TRUE');
WriteString('SQLPASSTHRU MODE','SHARED NOAUTOCOMMIT');
WriteString('SQLQRYMODE','SERVER');
end;
CloseKey;
Free;
end;