怎样检测网络中的电脑是否有安装SQL 2000


None.gif
引用SQL DMO组件
None.gif
// 取得本局域网内所有可用sql服务器名
None.gif
            cmbServer.Items.Clear();
None.gif            
try
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                SQLDMO.Application app 
= new SQLDMO.ApplicationClass();
InBlock.gif                SQLDMO.NameList list 
= app.ListAvailableSQLServers();
InBlock.gif                
int iCount = list.Count;
InBlock.gif            
InBlock.gif                
for(int i = 0; i < iCount; i ++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string sTemp = list.Item(i);
InBlock.gif                    
if(sTemp != null)
InBlock.gif                        cmbServer.Items.Add(sTemp);
ExpandedSubBlockEnd.gif                }

ExpandedBlockEnd.gif            }

None.gif            
catch
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                
//如果取得SQLDMO组件出错, 则默认把本机名写进去
InBlock.gif
                MessageBox.Show("无法取得服务器列表,可能是缺少SDLDMO.DLL!");
InBlock.gif                cmbServer.Items.Add(System.Net.Dns.GetHostName());
ExpandedBlockEnd.gif            }

None.gif为什么我用panyee(快乐王子)的那个例子一直出现“无法取得服务器列表,可能是缺少SDLDMO.DLL”,我有这个文件啊!
None.gif
None.gif如果用“http:
// xml.sz.luohuedu.net/xml/ShowDetail.asp?id=BCEAADFB-CFF3-4804-B3B3-6C7D6488982B”里的例子也不行会出现以下信息:
None.gif
" 未处理的“System.InvalidCastException”类型的异常出现在WindowsApplication1.exe 中
None.gif
其他信息:接口 SQLDMO.NameList 的 QueryInterface 失败。
None.gif怎么回事,请高手帮帮忙啊!
None.gif第一,你的sql server 版本不够。
None.gif 如果要使用SQLDMO.DLL就要去下载SQL sp2.
None.gif 第二,如果你想列出局域网内的所有的SQl server
None.gif 建议你用Sql server自带的 isql.exe 这个文件只要是sql server 
6 .5以上就可以了
None.gif 下面是源码:
None.gif  
string  fileName  =   " C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\Binn\\isql.exe " ;
None.gif            
if (System.IO.File.Exists(fileName))
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                System.Diagnostics.ProcessStartInfo processStartInfo 
= new System.Diagnostics.ProcessStartInfo(fileName,"-L");
InBlock.gif                processStartInfo.UseShellExecute 
= false;
InBlock.gif                processStartInfo.CreateNoWindow 
= true;
InBlock.gif                processStartInfo.RedirectStandardOutput 
= true;
InBlock.gif                processStartInfo.RedirectStandardError 
= true;
InBlock.gif                System.Diagnostics.Process process 
= System.Diagnostics.Process.Start(processStartInfo);
InBlock.gif                process.WaitForExit();
InBlock.gif                cboServerList.Items.Clear();
InBlock.gif                
int line = 1;
InBlock.gif                
string server = null;
InBlock.gif                
while(process.StandardOutput.Peek() > -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    server 
= process.StandardOutput.ReadLine().Trim();
InBlock.gif                    line 
+=1;
InBlock.gif                    
if ( line > 6)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        cboServerList.Items.Add(server);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    server 
= null;
ExpandedSubBlockEnd.gif                }

ExpandedBlockEnd.gif            }

None.gif            cboServerList.Items.Remove(System.Environment.MachineName);
None.gif            cboServerList.Items.Add(
" localhost " );
None.gif cboServerList是一个ComoBox
None.gif
None.gif你可以现在cmd中输入isql.exe 
- ? 看看参数序列中有没有你想要的
None.gif 至于说列出局域网内的sql server 要输入 isql 
- L就可以了
None.gif
private   void  cmbDatabase_Enter( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
//取得某服务器上的各个表名
InBlock.gif
            
InBlock.gif            
string strServer = cmbServer.Text;
InBlock.gif            
string strUid = txtUid.Text;
InBlock.gif            
if(strServer.Trim() != "" && strUid.Trim() != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string strPwd = txtPwd.Text;
InBlock.gif                
string strConn = "server=" + strServer + ";database=master;uid=" + strUid + ";pwd=" + strPwd;
InBlock.gif                SqlConnection conn 
= null;
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    conn 
= new SqlConnection(strConn);
InBlock.gif                    
string strSQL = "select * from sysdatabases order by dbid";
InBlock.gif                    SqlDataAdapter cmd 
= new SqlDataAdapter(strSQL, conn);
InBlock.gif                    DataSet ds 
= new DataSet();
InBlock.gif                    cmd.Fill(ds, 
"Databases");
InBlock.gif                    cmbDatabase.Items.Clear();
InBlock.gif                    
for(int i = 0; i < ds.Tables["Databases"].Rows.Count; i ++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
string strDb = ds.Tables["Databases"].Rows[i]["name"].ToString();
InBlock.gif                        cmbDatabase.Items.Add(strDb);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch(Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    MessageBox.Show(ex.ToString());
ExpandedSubBlockEnd.gif                }

InBlock.gif                
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(conn.State == ConnectionState.Open)
InBlock.gif                        conn.Close();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.Cursor = Cursors.Default;
ExpandedBlockEnd.gif        }

None.gif
None.gif
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值