Board index » delphi » SQLDMO Very interesting topic, but cannot use the _Database2

SQLDMO Very interesting topic, but cannot use the _Database2


2003-11-27 02:15:03 AM
delphi15
Hi! everyone!
I have problem with the DMO initiate the _Database2. Please check the code.
where it has the // Error _databse vs _Database2
Thank you,
Tin Le
Here is the codes:
Function TForm1.sLoadUDFuntions2(SourceServer:Boolean;strDB :
String):TStringList;
Var strUserID,
strPassword,
strSQLServer : String;
blnSecure : Boolean;
intItemCount : Integer;
dmo: _SQLServer2;
dmoOld: _SQLServer;
dmoDatabase : _Database2;
SQL_OBJ: oleVariant;
Begin
Result := TStringList.Create;
dmo := CoSQLServer2.Create;
dmoOld := CoSQLServer.Create;
If SourceServer Then Begin
strSQLServer := SSQLServer;
blnSecure := SLoginSecure;
strUserID := SUserID;
strPassword := SPassword;
End Else Begin
strSQLServer := TSQLServer;
blnSecure := TLoginSecure;
strUserID := TUserID;
strPassword := TPassword;
End;
dmo.Name := strSQLServer;
dmo.LoginSecure := blnSecure;
dmo.Login := strUserID;
dmo.Password := strPassword;
dmo.Connect(dmo.Name, dmo.Login, dmo.Password);
// dmoOld does not have UserDefinedFunctions, I can initiate the
dmoDatabase here
dmoDatabase := dmoOld.Databases.Item(strDB,Null);
dmoOld.Name := strSQLServer;
dmoOld.LoginSecure := blnSecure;
dmoOld.Login := strUserID;
dmoOld.Password := strPassword;
dmoOld.Connect(dmoOld.Name, dmoOld.Login, dmoOld.Password);
// dmo has UserDefinedFunctions, But I cannot initiate the dmoDatabase
here
dmoDatabase := dmo.Databases.Item(strDB,Null); // Error _databse vs
_Database2
{
For intItemCount := 1 To dmoDatabase.Tables.Count Do Begin
If Not dmoDatabase.Tables.Item(intItemCount, null).SystemObject Then
Begin
Result.Add(dmoDatabase.Tables.Item(intItemCount,null).Name);
End;
End;
}
end;
 
 

Re:SQLDMO Very interesting topic, but cannot use the _Database2

"Tin Le" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
Hi! everyone!
I have problem with the DMO initiate the _Database2. Please check the
code.
where it has the // Error _databse vs _Database2
// dmo has UserDefinedFunctions, But I cannot initiate the dmoDatabase
here
dmoDatabase := dmo.Databases.Item(strDB,Null); // Error _databse vs
_Database2
Try this:
dmoDatabase := dmo.Databases.Item(strDB,Null) as _Database2;
You could also temporarily switch to late bindung:
var
db_dispatch : OleVariant;
db_dispatch := dmo.Databases.Item(strDB,Null) as IDispatch;
// work with variable db_dispatch:
ShowMessage('# of Tables:'+db_dispatch.Tables.Count);
// release the Dispatch interface
db_dispatch := UnAssigned;
hth
Andreas
 

Re:SQLDMO Very interesting topic, but cannot use the _Database2

Quote
Try this:
dmoDatabase := dmo.Databases.Item(strDB,Null) as _Database2;
You could also temporarily switch to late bindung:
var
db_dispatch : OleVariant;
db_dispatch := dmo.Databases.Item(strDB,Null) as IDispatch;
// work with variable db_dispatch:
ShowMessage('# of Tables:'+db_dispatch.Tables.Count);
// release the Dispatch interface
db_dispatch := UnAssigned;
hth
Andreas
Thank you Adreas!
It works perfectly!
Here is another question. How to use object.script in delphi? it drives me
nuts.
Please help.
Thank you,
Tin Le