关闭 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固态盘不见了...

    IT头条

    Synology 更新 ActiveProtect Manager 1.1 以增强企业网络弹性和合规性

    00:43

    新的 Rubrik Agent Cloud 加速了可信的企业 AI 代理部署

    00:34

    宇树科技 G1人形机器人,拉动一辆重达1.4吨的汽车

    00:21

    Cloudera 调查发现,96% 的企业已将 AI 集成到核心业务流程中,这表明 AI 已从竞争优势转变为强制性实践

    02:05

    投资者反对马斯克 1 万亿美元薪酬方案,要求重组特斯拉董事会

    01:18

    技术热点

    大型网站的 HTTPS 实践(三):基于协议和配置的优化

    ubuntu下右键菜单添加新建word、excel文档等快捷方式

    Sublime Text 简明教程

    用户定义SQL Server函数的描述

    怎么在windows 7开始菜单中添加下载选项?

    SQL Server 2016将有哪些功能改进?

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

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