关闭 x
IT技术网
    技 采 号
    ITJS.cn - 技术改变世界
    • 实用工具
    • 菜鸟教程
    IT采购网 中国存储网 科技号 CIO智库

    IT技术网

    IT采购网
    • 首页
    • 行业资讯
    • 系统运维
      • 操作系统
        • Windows
        • Linux
        • Mac OS
      • 数据库
        • MySQL
        • Oracle
        • SQL Server
      • 网站建设
    • 人工智能
    • 半导体芯片
    • 笔记本电脑
    • 智能手机
    • 智能汽车
    • 编程语言
    IT技术网 - ITJS.CN
    首页 » SQL Server »检测局域网电脑是否有安装SQL Server数据库

    检测局域网电脑是否有安装SQL Server数据库

    2011-07-21 09:32:00 出处:ITJS
    分享

    本文主要介绍如何检测局域网中的电脑是否有安装SQL Server数据库,并将其列出的方法。接下来我们就开始介绍这一过程的实现。

    引用SQL DMO组件。

    //取得本局域网内所有可用sql服务器名   cmbServer.Items.Clear();   try   {   SQLDMO.Application app = new SQLDMO.ApplicationClass();   SQLDMO.NameList list = app.ListAvailableSQLServers();   int iCount = list.Count;   for(int i = 0; i < iCount; i ++)   {   string sTemp = list.Item(i);   if(sTemp != null)   cmbServer.Items.Add(sTemp);   }   }   catch   {   //假如取得SQLDMO组件出错, 则默认把本机名写进去   MessageBox.Show("无法取得服务器列表,可能是缺少SDLDMO.DLL!");   cmbServer.Items.Add(System.Net.Dns.GetHostName());   } 

    为什么我用panyee(快乐王子)的那个例子一直出现“无法取得服务器列表,可能是缺少SDLDMO.DLL”,我有这个文件啊!

    假如用“http://xml.sz.luohuedu.net/xml/ShowDetail.asp id=BCEAADFB-CFF3-4804-B3B3-6C7D6488982B”里的例子也不行会出现以下信息:

    "未处理的“System.InvalidCastException”类型的异常出现在WindowsApplication1.exe 中。

    其他信息:接口SQLDMO.NameList 的QueryInterface 失败。

    怎么回事,请高手帮帮忙啊!

    第一,你的SQL Server数据库版本不够。假如要使用SQLDMO.DLL就要去下载SQL sp2.

    第二,假如你想列出局域网内的所有的SQl server。建议你用Sql server自带的 isql.exe 这个文件只要是sql server 6.5以上就可以了。

    下面是源码:

    string fileName = "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isql.exe";   if(System.IO.File.Exists(fileName))   {   System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo(fileName,"-L");   processStartInfo.UseShellExecute = false;   processStartInfo.CreateNoWindow = true;   processStartInfo.RedirectStandardOutput = true;   processStartInfo.RedirectStandardError = true;   System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo);   process.WaitForExit();   cboServerList.Items.Clear();   int line = 1;   string server = null;   while(process.StandardOutput.Peek() > -1)   {   server = process.StandardOutput.ReadLine().Trim();   line +=1;   if ( line > 6)   {   cboServerList.Items.Add(server);   }   server = null;   }   }   cboServerList.Items.Remove(System.Environment.MachineName);   cboServerList.Items.Add("localhost"); 

    cboServerList是一个ComoBox。

    你可以现在cmd中输入isql.exe -? 看看参数序列中有没有你想要的。

    至于说列出局域网内的SQL Server数据库要输入 isql -L就可以了。

    private void cmbDatabase_Enter(object sender, System.EventArgs e)   {   //取得某服务器上的各个表名   string strServer = cmbServer.Text;   string strUid = txtUid.Text;   if(strServer.Trim() != "" && strUid.Trim() != "")   {   string strPwd = txtPwd.Text;   string strConn = "server=" + strServer + ";database=master;uid=" + strUid + ";pwd=" + strPwd;   SqlConnection conn = null;   try   {   conn = new SqlConnection(strConn);   string strSQL = "select * from sysdatabases order by dbid";   SqlDataAdapter cmd = new SqlDataAdapter(strSQL, conn);   DataSet ds = new DataSet();   cmd.Fill(ds, "Databases");   cmbDatabase.Items.Clear();   for(int i = 0; i < ds.Tables["Databases"].Rows.Count; i ++)   {   string strDb = ds.Tables["Databases"].Rows[i]["name"].ToString();   cmbDatabase.Items.Add(strDb);   }   }   catch(Exception ex)   {   MessageBox.Show(ex.ToString());   }   finally   {   if(conn.State == ConnectionState.Open)   conn.Close();   }   }   this.Cursor = Cursors.Default;   } 

    这样,我们就能检测到局域网内是否安装有SQL Server数据库,并能将其列出了。本文就介绍到这里,希望能对您有所帮助。

    上一篇返回首页 下一篇

    声明: 此文观点不代表本站立场;转载务必保留本文链接;版权疑问请联系我们。

    别人在看

    Destoon 模板存放规则及语法参考

    Destoon系统常量与变量

    Destoon系统目录文件结构说明

    Destoon 系统安装指南

    Destoon会员公司主页模板风格添加方法

    Destoon 二次开发入门

    Microsoft 将于 2026 年 10 月终止对 Windows 11 SE 的支持

    Windows 11 存储感知如何设置?了解Windows 11 存储感知开启的好处

    Windows 11 24H2 更新灾难:系统升级了,SSD固态盘不见了...

    小米路由器买哪款?Miwifi热门路由器型号对比分析

    IT头条

    Synology 对 Office 套件进行重大 AI 更新,增强私有云的生产力和安全性

    01:43

    StorONE 的高效平台将 Storage Guardian 数据中心占用空间减少 80%

    11:03

    年赚千亿的印度能源巨头Nayara 云服务瘫痪,被微软卡了一下脖子

    12:54

    国产6nm GPU新突破!砺算科技官宣:自研TrueGPU架构7月26日发布

    01:57

    公安部:我国在售汽车搭载的“智驾”系统都不具备“自动驾驶”功能

    02:03

    技术热点

    最全面的前端开发指南

    Windows7任务栏桌面下角的一些正在运行的图标不见了

    sql server快速删除记录方法

    SQL Server 7移动数据的6种方法

    SQL Server 2008的新压缩特性

    每个Java程序员必须知道的5个JVM命令行标志

      友情链接:
    • IT采购网
    • 科技号
    • 中国存储网
    • 存储网
    • 半导体联盟
    • 医疗软件网
    • 软件中国
    • ITbrand
    • 采购中国
    • CIO智库
    • 考研题库
    • 法务网
    • AI工具网
    • 电子芯片网
    • 安全库
    • 隐私保护
    • 版权申明
    • 联系我们
    IT技术网 版权所有 © 2020-2025,京ICP备14047533号-20,Power by OK设计网

    在上方输入关键词后,回车键 开始搜索。Esc键 取消该搜索窗口。