自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

檢測局域網(wǎng)電腦是否有安裝SQL Server數(shù)據(jù)庫

數(shù)據(jù)庫 SQL Server
怎樣檢測您所在的局域網(wǎng)是否安裝了SQL Server數(shù)據(jù)庫呢?怎樣查看數(shù)據(jù)庫的名稱并將其列出呢?本文就介紹實(shí)現(xiàn)這一過程的方法,希望能對(duì)讀者有所幫助。

本文主要介紹如何檢測局域網(wǎng)中的電腦是否有安裝SQL Server數(shù)據(jù)庫,并將其列出的方法。接下來我們就開始介紹這一過程的實(shí)現(xiàn)。

引用SQL DMO組件。

 

  1. //取得本局域網(wǎng)內(nèi)所有可用sql服務(wù)器名  
  2.  
  3. cmbServer.Items.Clear();  
  4.  
  5. try  
  6.  
  7. {  
  8.  
  9. SQLDMO.Application app = new SQLDMO.ApplicationClass();  
  10.  
  11. SQLDMO.NameList list = app.ListAvailableSQLServers();  
  12.  
  13. int iCount = list.Count;  
  14.  
  15. for(int i = 0; i < iCount; i ++)  
  16.  
  17. {  
  18.  
  19. string sTemp = list.Item(i);  
  20.  
  21. if(sTemp != null)  
  22.  
  23. cmbServer.Items.Add(sTemp);  
  24.  
  25. }  
  26.  
  27. }  
  28.  
  29. catch  
  30.  
  31. {  
  32.  
  33. //如果取得SQLDMO組件出錯(cuò), 則默認(rèn)把本機(jī)名寫進(jìn)去  
  34.  
  35. MessageBox.Show("無法取得服務(wù)器列表,可能是缺少SDLDMO.DLL!");  
  36.  
  37. cmbServer.Items.Add(System.Net.Dns.GetHostName());  
  38.  

 

為什么我用panyee(快樂王子)的那個(gè)例子一直出現(xiàn)“無法取得服務(wù)器列表,可能是缺少SDLDMO.DLL”,我有這個(gè)文件?。?/p>

如果用“http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=BCEAADFB-CFF3-4804-B3B3-6C7D6488982B”里的例子也不行會(huì)出現(xiàn)以下信息:

"未處理的“System.InvalidCastException”類型的異常出現(xiàn)在WindowsApplication1.exe 中。

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

怎么回事,請(qǐng)高手幫幫忙??!

***,你的SQL Server數(shù)據(jù)庫版本不夠。如果要使用SQLDMO.DLL就要去下載SQL sp2.

第二,如果你想列出局域網(wǎng)內(nèi)的所有的SQl server。建議你用Sql server自帶的 isql.exe 這個(gè)文件只要是sql server 6.5以上就可以了。

下面是源碼:

 

  1. string fileName = "C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\Binn\\isql.exe";  
  2.  
  3. if(System.IO.File.Exists(fileName))  
  4.  
  5. {  
  6.  
  7. System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo(fileName,"-L");  
  8.  
  9. processStartInfo.UseShellExecute = false;  
  10.  
  11. processStartInfo.CreateNoWindow = true;  
  12.  
  13. processStartInfo.RedirectStandardOutput = true;  
  14.  
  15. processStartInfo.RedirectStandardError = true;  
  16.  
  17. System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo);  
  18.  
  19. process.WaitForExit();  
  20.  
  21. cboServerList.Items.Clear();  
  22.  
  23. int line = 1;  
  24.  
  25. string server = null;  
  26.  
  27. while(process.StandardOutput.Peek() > -1)  
  28.  
  29. {  
  30.  
  31. server = process.StandardOutput.ReadLine().Trim();  
  32.  
  33. line +=1;  
  34.  
  35. if ( line > 6)  
  36.  
  37. {  
  38.  
  39. cboServerList.Items.Add(server);  
  40.  
  41. }  
  42.  
  43. server = null;  
  44.  
  45. }  
  46.  
  47. }  
  48.  
  49. cboServerList.Items.Remove(System.Environment.MachineName);  
  50.  
  51. cboServerList.Items.Add("localhost"); 

 

cboServerList是一個(gè)ComoBox。

你可以現(xiàn)在cmd中輸入isql.exe -? 看看參數(shù)序列中有沒有你想要的。

至于說列出局域網(wǎng)內(nèi)的SQL Server數(shù)據(jù)庫要輸入 isql -L就可以了。

 

  1. private void cmbDatabase_Enter(object sender, System.EventArgs e)  
  2.  
  3. {  
  4.  
  5. //取得某服務(wù)器上的各個(gè)表名  
  6.  
  7. string strServer = cmbServer.Text;  
  8.  
  9. string strUid = txtUid.Text;  
  10.  
  11. if(strServer.Trim() != "" && strUid.Trim() != "")  
  12.  
  13. {  
  14.  
  15. string strPwd = txtPwd.Text;  
  16.  
  17. string strConn = "server=" + strServer + ";database=master;uid=" + strUid + ";pwd=" + strPwd;  
  18.  
  19. SqlConnection conn = null;  
  20.  
  21. try  
  22.  
  23. {  
  24.  
  25. conn = new SqlConnection(strConn);  
  26.  
  27. string strSQL = "select * from sysdatabases order by dbid";  
  28.  
  29. SqlDataAdapter cmd = new SqlDataAdapter(strSQL, conn);  
  30.  
  31. DataSet ds = new DataSet();  
  32.  
  33. cmd.Fill(ds, "Databases");  
  34.  
  35. cmbDatabase.Items.Clear();  
  36.  
  37. for(int i = 0; i < ds.Tables["Databases"].Rows.Count; i ++)  
  38.  
  39. {  
  40.  
  41. string strDb = ds.Tables["Databases"].Rows[i]["name"].ToString();  
  42.  
  43. cmbDatabase.Items.Add(strDb);  
  44.  
  45. }  
  46.  
  47. }  
  48.  
  49. catch(Exception ex)  
  50.  
  51. {  
  52.  
  53. MessageBox.Show(ex.ToString());  
  54.  
  55. }  
  56.  
  57. finally  
  58.  
  59. {  
  60.  
  61. if(conn.State == ConnectionState.Open)  
  62.  
  63. conn.Close();  
  64.  
  65. }  
  66.  
  67. }  
  68.  
  69. this.Cursor = Cursors.Default;  
  70.  

 

 這樣,我們就能檢測到局域網(wǎng)內(nèi)是否安裝有SQL Server數(shù)據(jù)庫,并能將其列出了。本文就介紹到這里,希望能對(duì)您有所幫助。

【編輯推薦】

  1. 淺談Oracle Buffer Cache的優(yōu)化思路
  2. Linux系統(tǒng)下MySQL重要目錄和密碼管理
  3. 一個(gè)利用Oracle表的主外鍵關(guān)系實(shí)現(xiàn)級(jí)聯(lián)刪除的實(shí)例
  4. Oracle數(shù)據(jù)庫Guid作主鍵時(shí)執(zhí)行速度超慢的原因在哪里
  5. 利用PL/SQLDeveloper將CSV數(shù)據(jù)導(dǎo)入ORACLE對(duì)應(yīng)表中
責(zé)任編輯:趙鵬 來源: 博客園
相關(guān)推薦

2010-07-23 10:01:54

SQL Server

2010-07-08 15:55:25

SQL Server

2009-01-11 10:10:00

局域網(wǎng)網(wǎng)絡(luò)安全

2010-07-15 17:28:50

SQL Server

2009-03-03 13:51:15

2011-09-19 16:06:55

路由器局域網(wǎng)分段

2009-12-23 17:29:45

2011-07-21 17:06:42

MySQL數(shù)據(jù)庫局域網(wǎng)

2010-07-16 14:17:18

SQL Server

2010-06-18 09:31:51

SQL Server數(shù)

2010-09-02 09:07:53

2009-02-01 10:08:23

數(shù)據(jù)中心局域網(wǎng)虛擬化

2010-04-15 12:14:30

局域網(wǎng)無線網(wǎng)卡安裝

2011-08-17 14:12:18

無線局域網(wǎng)

2010-09-28 16:29:54

局域網(wǎng)DHCP協(xié)議

2010-09-16 13:02:23

2011-04-07 10:15:19

局域網(wǎng)路由器

2009-01-13 09:34:00

局域網(wǎng)管理部署

2010-06-09 10:38:05

局域網(wǎng)協(xié)議

2010-10-14 10:54:09

企業(yè)無線局域網(wǎng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)