呕血求教小问题~!~,赚分好机会啊(100分)

  • 主题发起人 主题发起人 zgdtxf
  • 开始时间 开始时间
Z

zgdtxf

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位高人指点,小弟不胜感激:
如何在delphi中不建立odbc或bde来用data access 的database控件来连接db2数据库??
或如何在程序中建立odbc连接????
 
难道大家都没有作过这方面的东西???
 
我也知道用ADO可以,不过现在只能用data access 的database控件来连接db2数据库
急!急!急!
 
找一些控件或许可以.
 
ZGDTXF怎么样通过ADO和AS400连接?用DELPHI程序去读取!能否详细指教
(或EMAIL给我)或者不用ADO,我现在遇到的问题是怎么建立DELPHI和
AS400连接?分不成问题!
我知道用IBM的CLIENTACCESS可以建立和EXCEL连接!
 
to lianzj:
你只要在adoconnection的CONNECTIONSTRING中加入参数,如下:
ConnectionString:='DRIVER={IBM DB2 ODBC DRIVER};user ID=xxxx;pwd=xxxx;server=xxxx;DATABASE=xxxx;dbalias=xxxx;';
注意一定要加上dbalias啊,别忘了给分哦
 
此问题太简单了;
1。用database控件连数据库;
先用database任意连一数据库,双击此控件,不是有很多参数吗,
把这些参数的搬到database.parampete.add('');
2。用ado连数据库,
如zgdrtxf;
 
to liuxiaouo:
用database控件连数据库时不是还要建立odbc的嘛!而且在有odbc的情况下双击database控件
只有如下参数:database=xxxx;alias=xxxx;在下面的parameters中只有USER NAME=xxxx;
如何" 把这些参数的搬到database.parampete.add('')"中请说明的详细一点,谢谢
 
to zgdtxf:
有没搞错,用Ctrl+C and Ctrl+V
够详细了吧,嘿嘿
 
to jedei:
那么你是如何在不建立odbc的情况下,用database控件连数据源的呢?
 
先要有DB2的客户端!
在动态的建一个DATABASE,设好他的参数
DATABSE。PARAM。VAULE[USER NAME] := ;
他的参数设定是根据BDE里面来的
 
不用 odbc 就必须自己找客户端。或者自己编程使用数据库自己的通信协议。我估计
没什么人知道如何这么干,而且没有任何通用性。

odbc 是最基础的数据库通讯方法,适用于所有的数据库。
 
以下是连接sql server
procedure TdmEasyData.dmEasyDataCreate(Sender: TObject);
begin
Database1.Connected:=false;
Database1.Params.Clear;
Database1.Params.Add('DATABASE NAME='+databasename);
Database1.Params.Add('SERVER NAME='+ServerName);
Database1.Params.Add('USER NAME='+UserName);
Database1.Params.Add('PASSWORD='+PassWord);
Database1.Params.Add('OPEN MODE=READ/WRITE');
Database1.Params.Add('SCHEMA CACHE SIZE=8');
Database1.Params.Add('BLOB EDIT LOGGING=');
Database1.Params.Add('LANGDRIVER=');
Database1.Params.Add('SQLQRYMODE=');
Database1.Params.Add('SQLPASSTHRU MODE=SHARED AUTOCOMMIT');
Database1.Params.Add('DATE MODE=0');
Database1.Params.Add('SCHEMA CACHE TIME=-1');
Database1.Params.Add('MAX QUERY TIME=300');
Database1.Params.Add('MAX ROWS=-1');
Database1.Params.Add('BATCH COUNT=200');
Database1.Params.Add('ENABLE SCHEMA CACHE=FALSE');
Database1.Params.Add('SCHEMA CACHE DIR=');
Database1.Params.Add('HOST NAME=');
Database1.Params.Add('APPLICATION NAME=');
Database1.Params.Add('NATIONAL LANG NAME=');
Database1.Params.Add('ENABLE BCD=TRUE');
Database1.Params.Add('TDS PACKET SIZE=4096');
Database1.Params.Add('BLOBS TO CACHE=64');
Database1.Params.Add('BLOB SIZE=32');
try
ss:=databasename;
Database1.Connected:=true;
except
Application.MessageBox(pchar('数据库'+ss+'连接失败!'),'错误',MB_OKCANCEL + MB_DEFBUTTON1);
exit;
end;
end;
 
liuxiaouo说的一样的要BDE 莫听他乱说
 
楼上的;
BDE环境都没有,怎样用database;
提问者的意思我想应该是不要手手工配置bde别名或者ODBC;


 
同意liuxiaouo
既然用了TDATABASE,就是说跟BDE绑上了。
可以不手工配置BDE别名,因为可以用程序自己建立。
或者干脆程序安装时就把别名建立起来就完了。
 
谢谢各位帮忙,其实db2确实和它的客户端关系密切,它要用到一个db2自带的动态库的。
我实在没有办法就用动态创建odbc的方法了,问题变相解决了。
给大家加分了
to xianjun:"程序安装时就把别名建立起来"如何实现???
 
像InstallShield等安装程序制作工具都提供这个功能的, 就是帮你建立BDE的别名。
不过也没必要了, 因为可以在程序中自己建立的, 你可以参考一下我以前用过
的一个建立别名的控件:

// Filename: AliasEd.pas
// Version : 01.02
// Date : 29/03/97
// Author : Glenn Davies
//
// Description:
// BDE alias management component.
//
// History:
// 14/06/97 - V01.03
// Revised for compatibility with Delphi 3.
// 29/03/97 - V01.02
// Added GetDriverList and GetDriverParams methods for completeness.
// 30/05/96 - V01.01
// Now uses methods and properties of Session rather than BDE functions.
// As a result, most methods are now procedures which raise exceptions if
// an error occurs rather than Boolean functions. Methods now accept
// TStrings objects as parameters rather than only TStringList objects.
// 16/05/96 - V01.00
// Initial version.

unit AliasEd;

interface

uses
SysUtils, Classes, DBTables;

//------------------------------------------------------------------------------

type

{TAliasEditor class declaration}

TAliasEditor = class(TComponent)
private
fParams: TStringList;
fConfigMode: TConfigMode;
fOldConfigMode: TConfigMode;
protected
procedure InitBDE;
procedure RestoreConfigMode;
procedure SetConfigMode;
public
constructor Create(owner: TComponent); override;
destructor Destroy; override;
procedure Add(const alias, driver: String; the_params: TStrings);
procedure Delete(const alias: String);
function Exists(const alias: String): Boolean;
procedure Modify(const alias: String; the_params: TStrings);
procedure GetAliasList(the_params: TStrings);
function GetDriver(const alias: String): String;
procedure GetDriverParams(const driver_name: String; the_params: TStrings);
procedure GetDriverList(the_params: TStrings);
procedure GetParams(const alias: String; the_params: TStrings);
function GetPath(const alias: String): String;
function GetType(const alias: String): String;
property Params: TStringList read fParams write fParams;
published
property ConfigMode: TConfigMode read fConfigMode write fConfigMode default [cfmPersistent];
end;

//------------------------------------------------------------------------------

procedure Register;

//------------------------------------------------------------------------------

implementation

//------------------------------------------------------------------------------

{TAliasEditor class implementation}

//------------------------------------------------------------------------------

procedure TAliasEditor.InitBDE;
begin
if not(Session.Active) then
Session.Active := True;
end;

//------------------------------------------------------------------------------

procedure TAliasEditor.RestoreConfigMode;
begin
Session.ConfigMode := fOldConfigMode;
end;

//------------------------------------------------------------------------------

procedure TAliasEditor.SetConfigMode;
begin
fOldConfigMode := Session.ConfigMode;
Session.ConfigMode := fConfigMode;
end;

//------------------------------------------------------------------------------

constructor TAliasEditor.Create(owner: TComponent);
begin
inherited Create(owner);
fParams := TStringList.Create;
fConfigMode := [cfmPersistent];
end;

//------------------------------------------------------------------------------

destructor TAliasEditor.Destroy;
begin
fParams.Free;
inherited Destroy;
end;

//------------------------------------------------------------------------------

// Add a new alias.

procedure TAliasEditor.Add(const alias, driver: String; the_params: TStrings);
begin
InitBDE;
SetConfigMode;
try
Session.AddAlias(alias, driver, the_params);
Session.SaveConfigFile;
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Delete an existing alias.

procedure TAliasEditor.Delete(const alias: String);
begin
InitBDE;
SetConfigMode;
try
Session.DeleteAlias(alias);
Session.SaveConfigFile;
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Check if an alias exists.

function TAliasEditor.Exists(const alias: String): Boolean;
begin
result := False;
InitBDE;
SetConfigMode;
try
result := Session.IsAlias(alias);
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Modify an existing alias.

procedure TAliasEditor.Modify(const alias: String; the_params: TStrings);
begin
InitBDE;
SetConfigMode;
try
Session.ModifyAlias(alias, the_params);
Session.SaveConfigFile;
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Get a list of available aliases.

procedure TAliasEditor.GetAliasList(the_params: TStrings);
begin
InitBDE;
SetConfigMode;
try
Session.GetAliasNames(the_params);
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Get the driver name for an alias.

function TAliasEditor.GetDriver(const alias: String): String;
begin
InitBDE;
SetConfigMode;
try
result := Session.GetAliasDriverName(alias);
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Get the default parameters for specified driver

procedure TAliasEditor.GetDriverParams(const driver_name: String; the_params: TStrings);
begin
InitBDE;
Session.GetDriverParams(driver_name,the_params);
end;

//------------------------------------------------------------------------------

// Get a list of currently installed drivers

procedure TAliasEditor.GetDriverList(the_params: TStrings);
begin
InitBDE;
Session.GetDriverNames(the_params);
end;

//------------------------------------------------------------------------------

// Get the parameters for an alias.

procedure TAliasEditor.GetParams(const alias: String; the_params: TStrings);
begin
InitBDE;
SetConfigMode;
try
Session.GetAliasParams(alias, the_params);
finally
RestoreConfigMode;
end;
end;

//------------------------------------------------------------------------------

// Get the path for an alias.

function TAliasEditor.GetPath(const alias: String): String;
var
the_params: TStringList;
begin
the_params := TStringList.Create;
try
GetParams(alias,the_params);
result := the_params.Values['PATH'];
finally
the_params.Free;
end;
end;

//------------------------------------------------------------------------------

// Get the type of an alias.

function TAliasEditor.GetType(const alias: String): String;
var
the_params: TStringList;
begin
the_params := TStringList.Create;
try
GetParams(alias,the_params);
result := the_params.Values['TYPE'];
finally
the_params.Free;
end;
end;

//------------------------------------------------------------------------------

procedure Register;
begin
RegisterComponents('Samples', [TAliasEditor]);
end;

//------------------------------------------------------------------------------

end.
 
后退
顶部