delphi - How to enumerate MSSQL Servers from a 64-bit client app? -


i'm looking way of enumerating ms sql servers on local network 64-bit delphi application. method i've used far on 32-bit works fine contains assembly code won't compile on 32-bit. can't seem find way of enumerating servers 64-bit client.

the code cannot compile this:

function ptcreateadoobject(const classid: tguid): iunknown; var   status: hresult;   fpucontrolword: word; begin   asm     fnstcw fpucontrolword   end;   status := cocreateinstance(               class_recordset,               nil,               clsctx_inproc_server or clsctx_local_server,               iunknown,               result);   asm     fnclex     fldcw fpucontrolword   end;   olecheck(status); end; 

example here adopted x64, compatible both, x32/x64 systems.

uses   activex, comobj, oledb, db, adoint, adodb;  function createadoobject(const classid: tguid): iunknown; var   status: hresult; {$ifdef cpux86}   fpucontrolword: word; {$endif cpux86} begin  {$ifdef cpux86}   asm     fnstcw  fpucontrolword   end; {$endif cpux86}   status := cocreateinstance(classid, nil, clsctx_inproc_server or     clsctx_local_server, iunknown, result); {$ifdef cpux86}   asm     fnclex     fldcw fpucontrolword   end; {$endif cpux86}   if (status = regdb_e_classnotreg)     raise exception.create('error')   else     olecheck(status); end;  procedure listavailablesqlservers(names: tstringlist); var   rscon: adorecordsetconstruction;   rowset: irowset;   sourcesrowset: isourcesrowset;   sourcesrecordset: _recordset;   sourcesname, sourcestype: tfield; begin   sourcesrecordset := createadoobject(class_recordset) _recordset;   rscon := sourcesrecordset adorecordsetconstruction;    sourcesrowset := createcomobject(progidtoclassid('sqloledb enumerator')) isourcesrowset;    olecheck(sourcesrowset.getsourcesrowset(nil, irowset, 0, nil, iunknown(rowset)));    rscon.rowset := rowset;    tadodataset.create(nil)    try      recordset := sourcesrecordset;      sourcesname := fieldbyname('sources_name');      sourcestype := fieldbyname('sources_type');      names.beginupdate;      names.clear;      try         while not eof         begin           if (sourcestype.asinteger = dbsourcetype_datasource) ,              (sourcesname.asstring <> '')                        names.add(sourcesname.asstring);           next;         end;              names.endupdate;      end;        free;   end; end;  procedure getserver; var   oitems: tstringlist; begin   oitems:= tstringlist.create;   try     listavailablesqlservers(oitems);     // oitems     showmessage(oitems.text);       oitems.free;   end; end; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -