Get all database server lists in the LAN

zhaozj2021-02-16  108

Using system;

Using system.drawing;

Using system.collections;

Using system.componentmodel;

Using system.windows.forms;

Using system.data;

?

Using sqldmo;

?

Namespace Testsqldmo

{

?????? ///

?????? /// Form1's summary description. ?????? ///

?????? public class form1: system.windows.forms.form

?????? {

????????????? private system.windows.Forms.Button Button1;

?????????????? ///

?????????????? // The required designer variable. ?????????????? ///

????????????? private system.componentmodel.container components = null;

?

????????????? public form1 ()

????????????? {

????????????????????

????????????????????? // Windows Form Designer Support

????????????????????

???????????????????? INITIALIZECMOMPONENT ();

?

????????????????????

?????????????????????????????? / Todo: Add any constructor code after INITIALIZECOMPONENT call

????????????????????

?????????????}

?

?????????????? ///

?????????????? /// cleaning all the resources being used. ?????????????? ///

????????????? protected override void dispose (Bool Disposing)

????????????? {

???????????????????? f (disposing)

???????????????????? {

??????????????????????????? IF (COMPONENTS! = NULL)

??????????????????????????? {

?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

???????????????????????????}

????????????????????}

???????????????????? Base.dispose (Disposing);

?????????????}

?

????????????? #Region Windows Form Designer Generated Code

?????? ?????? ///

?????????????? /// designer supports the required method - do not use the code editor to modify ????????????? // This method . ?????????????? ///

????????????? private vid initializecomponent ()

????????????? {

???????????????????? this.Button1 = new system.windows.Forms.Button ();

????????????????????? this.suspendlayout ();

????????????????????

????????????????????? // button1

?????????????????????????????????????????? THIS.BUTTON1.LOCATION = New System .Drawing.point (104, 192);

???????????????????? this.button1.name = "button1";

????????????????????? this.button1.taBindex = 0;

???????????????????? this.Button1.Text = "Button1";

????????????????????? this.button1.click = new system.eventhandler (this.button1_click);

????????????????????

????????????????????? // Form1

????????????????????

???????????????????? this.autoscalebasesize = new system.drawing.size (6, 14);

???????????????????? this.clientsize = new system.drawing.size (292, 266);

?????????????????????hiscontrols.addrange (new system.windows.forms.control [] {

??????????????????????????????????????????? ??????????????????????????????????????????? ????????????????????????????????????? this.button1}

???????????????????? this.name = "form1";

????????????????????? this.text = "Form1";

???????????????????? this.ResumeLayout (FALSE);

?

?????????????}

????????????? #endregion

?

?????????????? ///

????????????? /// The main entry point for the application. ?????????????? ///

????????????? [statneready]

????????????? static void

Main

()

????????????? {

???????????????????? system.windows.Forms.Application.run (New Form1 ());

?????????????}

?

????????????? private void button1_click (Object Sender, System.Eventargs E)

????????????? {

???????????????????? sqldMo.applicationclassclass SQLAPP = new SqldMo.applicationClass ();

???????????????????? sqldMo.namelist name

???????????????????? I N = 0;

?

????????????????????? Namelist = sqlapp.listavailableSQLSERVERS ();

?

???????????????????? for (i = 1; I

???????????????????? {

???????????????????????????? MessageBox.show (Namelist.Item (i) .tostring ()); ??????? ?????????????}

?????????????}

??????}

}

Get all databases in SQL Server and tables

?

????????????? private void button1_click (Object Sender, System.Eventargs E)

????????????? {

???????????????????? sqldmo.appLication sqlapp = new sqldMo.applicationclass ();

???????????????????? SqldMo.sqlServer Server = new SqldMo.sqlServerClass ();

???????????????????? server.connect (TXTSERVER.TEXT.TRIM (), txtuser.text.trim (), txtpass.text.trim ());

???????????????????? String starts = ""

???????????????????? String strrow = ""

???????????????????? Strrow = ("#### ??" server.databases.count "? ######");

???????????????????? response.write (strrow);

????????????????????? for (INT i = 1; i

???????????????????? {

???????????????????????????? Strrow = ("======== ??" i "?? == ======== " Server.Databases.Item (i," sa "). Tables.count =============");

???????????????????????????? Strrow = (Server.Databases.ItemByid (i) .name);

???????????????????????????

??????????????????????????? Response.write (strrow);

// ??????????????????????????? Lstname.Items.Add (Server.Databases.Item.);

??????????????????????????? for (INT J = 1; J

??????????????????????????? {

??????????????????????????? Strrow = ""

??????????????????????????????????? SQLDMO.TABLES TABLES = Server.Databases.Item (i, "sa" .TABLES;

??????????????????????????????????? STRTABLES = Tables.Item (J, "DBO"). ID "------" Tables.Item (J, "DBO"). Name "------" TABLES.ITEM (J, "DBO"). Owner? "---- - " Tables.Item (J," DBO "). Application.name ??; ????????????????????? ????? STRTABLES = "&&&?" J "&&&";

??????????????????????????????????? Strrow = (STRTABLES);

???????????????????????????????????Ri

???????????????????????????}

???????????????????????????

??????????????????????????? Strrow = ("****************** ********** ");

??????????????????????????? Response.write (strrow);

???????????????????????????

????????????? ??????}

To add a reference sqldmo.dll

You have installed SQLServer2000, and find it in adding a reference

It is best to use SQLDMO.DLL of SQL Server 2000 SP3

转载请注明原文地址:https://www.9cbs.com/read-11185.html

New Post(0)