3.1 Get list of LAN available servers
When designing software, we often rack their brains easily. What we think is that customers. Make customers get the most friendly software interface is our pursuit. So when making a database connection configuration program, we will need to let the customer choose the server name, enter the username, password, etc. How to get the list of SQLDMO questions on SQLDMO is also available. Let's take the following how to get the list of available servers.
Here, the first object we use is sqldmo.applicationclass (). Through this object, we can get the database instance list, get the version number of SQL-DMO and set blocking time-out.
2.1.1
). Here, I only tell how to get the database instance list. code show as below:
/ ** /
///
public
ArrayList GetServerList ()
{SQLDMO.ApplicationClass oApp = new SQLDMO.ApplicationClass (); ArrayList alTemp = new ArrayList (); try {SQLDMO.NameList iServerList = oApp.ListAvailableSQLServers (); if (iServerList = null!) {For (int i = 1; i <= IServerList.count; i ) {altemp.add (iServerList.Item (i) .tostring ());}}}}}} Catch {Return NULL;}}}
In the above code, we call
ListavailableSqlServers () This method. It returns a list of a current LAN for server instance to sqldMo.namelist
interface. All of the server names can be obtained by interface. (Note: In the use of this method, you need to hit the patch of SQLServer2000sp3, otherwise the QueryInterface failed in interface sqldmo.namelist will appear.)