作者:唯一的你b | 来源:互联网 | 2023-09-11 01:25
小弟在delphi6下做了一个基于数据库的程序,用installshieldexpress5打包,现在有个问题是:如何在目标机器上创建ODBC数据源呢?此问题困扰小弟许久,望各兄台不吝赐教!
小弟在delphi6下做了一个基于数据库的程序,用installshield express5打包,现在有个问题是:如何在目标机器上创建ODBC数据源呢?此问题困扰小弟许久,望各兄台不吝赐教!
9 个解决方案
最好用ADO的了,不需要配置ODBC的
InnoSetup简单易用的
不要再用BDE了!
我以前写的一个动态设置ODBC的单元,所有的ODBC其实都写有注册表里,看看就知道了
没用过IS,不过想来应该也可以在安装过程中创建ODBC的
//动态设置ODBC数据源
unit ODBC;
interface
uses
Windows,SysUtils, Forms,Registry;
procedure ODBCCreate();
implementation
procedure ODBCCreate();
var
RegODBC:Tregistry;
begin
Try
RegODBC:=Tregistry.Create;
RegODBC.RootKey:=HKEY_CURRENT_USER;
RegODBC.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources',true);
RegODBC.WriteString('MyODBC','Microsoft Visual FoxPro Driver');
RegODBC.CloseKey;
if RegODBC.OpenKey('\Software\ODBC\ODBC.INI\MyODBC',True) then
begin
RegODBC.WriteString('BackgroundFetch','Yes');
RegODBC.WriteString('Collate','Machine');
RegODBC.WriteString('deleted','Yes');
RegODBC.WriteString('Description','');
RegODBC.WriteString('Driver',ExtractFilePath(Application.ExeName)+'vfpodbc.dll');
RegODBC.WriteString('Exclusive','NO');
RegODBC.WriteString('Null','Yes');
RegODBC.WriteString('SetNoCountOn','NO');
RegODBC.WriteString('SourceDB',ExtractFilePath(Application.ExeName));
RegODBC.WriteString('SourceType','DBF');
end
else
begin
application.MessageBox('无法创建ODBC数据源,请确认注册表未写保护','警告',mb_ok);
end;
Finally
RegODBC.CloseKey;
RegODBC.free;
end;
end;
end.
我是用ADO做的呀,也配置数据源了,是不是做得不对呀?
knife_s(人生常恨水常东) 大哥,if RegODBC.OpenKey('\Software\ODBC\ODBC.INI\MyODBC',True) then后的那几句话有点看不懂,我是在Access下建的数据库,也要这样写吗?
在Delphi里调用API函数动态建立ODBC数据源。
SQLConfigDataSource(hwndParent: Integer;
fRequest: Integer;
lpszDriverString: String;
lpszAttributes: String): Integer;
调用状态下使用:
function SQLConfigDataSource(hwndParent: Integer; fRequest: Integer;lpszDriverString: String; lpszAttributes: String): Integer;stdcall;external 'ODBCCP32.DLL';
建立SQLSERVER的ODBC:
SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,'SQL Server','DSN=Record_ODBC'+ chr(0) +'Server=(local)'+ chr(0) +'Database=master'+ chr(0) +'Description=DragonPC SQLServer ODBC Source'+ chr(0));
{ DSN:你的ODBC数据源名称。
Server:你的数据库服务器名称,使用(local)指的是本地计算机安装的数据库。注:最新的SQL Server 2000支持一台计算机运行多个SQL Server服务,这个时候你需要指定SqlSever的InstanceName。
Address:指定SQL Server服务器的网络IP地址。
Database:指定默认数据库名称。
Language:指定默认语言。
Description:备注信息。}
installshield express5
支持配置odbc阿,看下就知道!!!
用ado这样连不就行了?
var
constr:string;
str_TestId: string;
begin
try
StrExePath := extractfilepath(application.ExeName);//取得当前应用程序的路径
//配置数据库
ADOConnection1.LoginPrompt := false;
constr:='Provider=Microsoft.Jet.OLEDB.4.0;';
//constr:=constr+'Password="N4S7=y6k0s0n=K8Y9";User ID=;';
constr:=constr+'Password="";User ID=;';
constr:=constr+'Data Source='+StrExePath+'data\lms.mdb;';
constr:=constr+'Mode=Share Deny None;Extended Properties="";';
constr:=constr+'Locale Identifier=2052;Jet OLEDB:System database="";';
constr:=constr+'Jet OLEDB:Registry Path="";';
constr:=constr+'Jet OLEDB:Database Password=nsky;';
constr:=constr+'Jet OLEDB:Engine Type=5;';
constr:=constr+'Jet OLEDB:Database Locking Mode=1;';
constr:=constr+'Jet OLEDB:Global Partial Bulk Ops=2;';
constr:=constr+'Jet OLEDB:Global Bulk TransactiOns=1;';
constr:=constr+'Jet OLEDB:New Database Password="";';
constr:=constr+'Jet OLEDB:Create System Database=False;';
constr:=constr+'Jet OLEDB:Encrypt Database=False;';
constr:=constr+'Jet OLEDB:Don''t Copy Locale on Compact=False;';
constr:=constr+'Jet OLEDB:Compact Without Replica Repair=False;';
constr:=constr+'Jet OLEDB:SFP=False';
adoconnection1.ConnectionString:=constr;
adoconnection1.Connected:=true;
except
Application.MessageBox(
'数据库连接失败!',
'提示',MB_OK + MB_DEFBUTTON1 + MB_ICONINFORMATION);
exit;
end;
http://www.56kc.com/technology.aspx
Wise打包工具的使用事例
配ODBC很简单,引用一下原来的配置就可以了