打印本文 打印本文 关闭窗口 关闭窗口
用API得到局域网中可用SqlServer服务器列表
作者:武汉SEO闵涛  文章来源:敏韬网  点击数6296  更新时间:2007/11/14 12:58:41  文章录入:mintao  责任编辑:mintao

无意中找到了以前的一个C#程序,觉得好用发到这里以便和大家共享一下,其实这个代码我是抄别人过来的,原作者不详,觉得写的好就和大家共享一下了程序实现了用API来得到SqlServer服务器列表的功能,我觉得比用SQLDEMO组件更有意义,代码如下:

/// <summary>

/// 获取网内的数据库服务器名称

/// </summary>

public class SqlLocator

{

     [System.Runtime.InteropServices.DllImport("odbc32.dll")]

     private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);

     [System.Runtime.InteropServices.DllImport("odbc32.dll")]

     private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);

     [System.Runtime.InteropServices.DllImport("odbc32.dll")]

     private static extern short SQLFreeHandle(short hType, IntPtr handle);

     [System.Runtime.InteropServices.DllImport("odbc32.dll",CharSet= System.Runtime.InteropServices.CharSet.Ansi)]

     private static extern short SQLBrowseConnect(IntPtr hconn, System.Text.StringBuilder inString,

         short inStringLength, System.Text.StringBuilder outString,

[1] [2] [3] [4] [5] [6] [7]  下一页

打印本文 打印本文 关闭窗口 关闭窗口