我在网上看过一个用BCB写的动态配置SQL Server 2000 ODBC数据源驱动程序,创建数据库,表的程序。
这样就节省了用户动手建SQL Server 2000 ODBC数据源驱动程序,数据库的麻烦。用Delphi怎样做这个程序?????
sunspeedzy(子秦) 是这样给我代码的,可我就是不能运行,哪位大哥能帮我编译一下,打包发给我,
邮箱:[email protected] 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;
这样就节省了用户动手建SQL Server 2000 ODBC数据源驱动程序,数据库的麻烦。用Delphi怎样做这个程序?????
sunspeedzy(子秦) 是这样给我代码的,可我就是不能运行,哪位大哥能帮我编译一下,打包发给我,
邮箱:[email protected] 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;
var
DSN:string;
Server:string;
DBName:string;
SourceDB:string;
SourceType:String;
Const
ODBC_ADD_DSN = 1;
begin
DSN:='SMS';
Server:='(Local)';
DBName:='DBAuto';
SourceDB:=ExtractFilePath(Application.ExeName)+'appDATA\dautocrm\dautocrm.dbc';;
SourceType:='DBC';
if (DSN<>'') and (Server<>'') and (DBName<>'') then
begin
SQLConfigDataSource(0, ODBC_ADD_DSN,'Microsoft Visual Foxpro Driver',
'DSN='+ DSN + chr(0) +
'SourceDB='+ SourceDB + chr(0) +
'SourceType='+ SourceType + chr(0) +
'Description=ODBC Source'+ chr(0));
end;
end;
[Error] Unit1.pas(43): Undeclared identifier: 'SQLConfigDataSource'