// ================================================ ======================================= //
////
// Function getsqlservers //
//// Obtain all the SQL services of the Local Machine
// Purpose get the local SQL servers //
////
// Argment //
////
// Return local SQL Server LIST //
////
// Author chenhuicong 2010-12-24 //
////
// ================================================ ======================================= //
Export prototype list getsqlservers ();
function list getsqlservers ()
Object objsqlservers, objitem, objaqldmoapp;
string szsqldmosqlserver, szsqldmoapp, szitem, szsqlservicename1, szsqlservicename;
List listid;
Number nitemcnt, nstep, ntype, nsize, nresult;
begin
/* nstep = 0;
szsqldmoapp = "sqldmo. application ";
set objaqldmoapp = Createobject (szsqldmoapp);
try
set objitem = objaqldmoapp. listavailablesqlservers ();
nitemcnt = objitem. count;
nstep = 1;
while (nstep <5)
szitem = objitem. item (nstep);
If (szitem [0] = "(") Then
listaddstring (listid, szitem, after);
endif;
nstep ++;
endwhile;
catch
listid = nothing;
objitem = nothing;
endcatch;
If (szsqlservicename1 = "") Then
szsqlservicename = "MSSQL";
listaddstring (listid, szsqlservicename, after);
elseif (szsqlservicename1! = "MSSQLServer") Then
szsqlservicename = "MSSQL $" + szsqlservicename1;
listaddstring (listid, szsqlservicename, after );
else
szsqlservicename = szsqlservicename1;
listaddstring (listid, szsqlservicename, after);
endif;
*/
listid = listcreate (stringlist);
// obtain the server name
regdbsetdefaultroot (HKEY_LOCAL_MACHINE );
nresult = regdbgetkeyvalueex ("Software \ Microsoft SQL Server", "installedinstances", ntype, szsqlservicename1, nsize);
If (nresult <0) then
szsqlservicename = "MSSQL";
else
listaddstring (listid, "(local)", after);
endif;
nresult = regdbgetkeyvalueex ("SOFTWARE \ Microsoft SQL Server \ sqlexpress \ setup", "sqlpath", ntype, szsqlservicename1, nsize );
If (nresult <0) Then
szsqlservicename = "MSSQL";
else
listaddstring (listid, "(local) \ Express ", after);
endif;
return listid;
end;