using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
?
using SQLDMO;
?
namespace TestSQLDMO
{
?????? ///
?????? /// Form1 的摘要说明。
?????? ///
?????? public class Form1 : System.Windows.Forms.Form
?????? {
????????????? private System.Windows.Forms.Button button1;
????????????? ///
????????????? /// 必需的设计器变量。
????????????? ///
????????????? private System.ComponentModel.Container components = null;
?
????????????? public Form1()
????????????? {
???????????????????? //
???????????????????? // Windows 窗体设计器支持所必需的
???????????????????? //
???????????????????? InitializeComponent();
?
???????????????????? //
???????????????????? // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
???????????????????? //
????????????? }
?
????????????? ///
????????????? /// 清理所有正在使用的资源。
????????????? ///
????????????? protected override void Dispose( bool disposing )
????????????? {
???????????????????? if( disposing )
???????????????????? {
??????????????????????????? if (components != null)
??????????????????????????? {
?????????????????????????????????? components.Dispose();
??????????????????????????? }
???????????????????? }
???????????????????? base.Dispose( disposing );
????????????? }
?
????????????? #region Windows Form Designer generated code
?????? ?????? ///
????????????? /// 设计器支持所需的方法 - 不要使用代码编辑器修改
????????????? /// 此方法的内容。
????????????? ///
????????????? private void 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);
???????????????????? this.Controls.AddRange(new System.Windows.Forms.Control[] {
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ? this.button1});
???????????????????? this.Name = "Form1";
???????????????????? this.Text = "Form1";
???????????????????? this.ResumeLayout(false);
?
????????????? }
????????????? #endregion
?
????????????? ///
????????????? /// 应用程序的主入口点。
????????????? ///
????????????? [STAThread]
????????????? static void Main ()
????????????? {
???????????????????? System.Windows.Forms.Application.Run(new Form1());
????????????? }
?
????????????? private void button1_Click(object sender, System.EventArgs e)
????????????? {
???????????????????? SQLDMO.ApplicationClass sqlApp = new SQLDMO.ApplicationClass();
???????????????????? SQLDMO.NameList nameList;
???????????????????? int i = 0;
?
???????????????????? nameList = sqlApp.ListAvailableSQLServers();
?
???????????????????? for(i=1;i < span>
???????????????????? {
??????????????????????????? MessageBox.Show(nameList.Item(i).ToString());
???????????????????? }
????????????? }
?????? }
}
获得SQLServer中所有的数据库中和表
?
????????????? 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 strTables="";
???????????????????? string strRow="";
???????????????????? strRow+=("####?? "+ server.Databases.Count +"? #######");
???????????????????? Response.Write(strRow);
???????????????????? for(int i=1 ; i< server.Databases.Count;i++)
???????????????????? {
??????????????????????????? strRow +=("========?? "+i+"?? =========="+server.Databases.Item(i,"sa").Tables.Count+"=============");
??????????????????????????? strRow +=(server.Databases.ItemByID(i).Name );
???????????????????????????
??????????????????????????? Response.Write(strRow);
//????????????????????????? lstName.Items.Add(server.Databases.ItemByID(i).Status? );
??????????????????????????? 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);
?????????????????????????????????? Response.Write(strRow);
??????????????????????????? }
???????????????????????????
??????????????????????????? strRow =("****************************");
??????????????????????????? Response.Write(strRow);
???????????????????????????
????????????? ?????? }
要添加引用sqldmo.dll
你安装了SqlServer2000 就有了,在添加引用中找它
最好使用SQL Server 2000的SP3的sqldmo.dll