Click here to Skip to main content
15,916,835 members
Home / Discussions / C#
   

C#

 
GeneralRe: DirectX Pin
Jeremy Kimball30-Jun-04 4:43
Jeremy Kimball30-Jun-04 4:43 
GeneralRe: DirectX Pin
Heath Stewart30-Jun-04 5:47
protectorHeath Stewart30-Jun-04 5:47 
GeneralRe: DirectX Pin
MKlucher30-Jun-04 6:52
MKlucher30-Jun-04 6:52 
GeneralProblem with appending rtf data to a rich text box Pin
Ravikumar_mv29-Jun-04 23:13
Ravikumar_mv29-Jun-04 23:13 
GeneralRe: Problem with appending rtf data to a rich text box Pin
Ravikumar_mv30-Jun-04 2:00
Ravikumar_mv30-Jun-04 2:00 
GeneralRe: Problem with appending rtf data to a rich text box Pin
Dave Kreskowiak30-Jun-04 12:17
mveDave Kreskowiak30-Jun-04 12:17 
Questionhow to get sqlserver names in local net Pin
huangjinzhansh29-Jun-04 22:17
huangjinzhansh29-Jun-04 22:17 
AnswerRe: how to get sqlserver names in local net Pin
Guinness4Strength30-Jun-04 6:13
Guinness4Strength30-Jun-04 6:13 
This will do it
private const short SQL_HANDLE_ENV = 1;
private const short SQL_HANDLE_DBC = 2;
private const int SQL_ATTR_ODBC_VERSION = 200;
private const int SQL_OV_ODBC3 = 3;
private const short SQL_SUCCESS = 0;
private const short SQL_NEED_DATA = 99;
private const short DEFAULT_RESULT_SIZE = 1024;
private const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";
[DllImport("odbc32.dll")]
private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
[DllImport("odbc32.dll")]
private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
[DllImport("odbc32.dll")]
private static extern short SQLFreeHandle(short hType, IntPtr handle); 
[DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
private static extern short SQLBrowseConnect(IntPtr hconn, StringBuilder inString, 
	short inStringLength, StringBuilder outString, short outStringLength,
	out short outLengthNeeded);

static public string[] GetSQLServers()
{
	string[] retval = null;
	string txt = string.Empty;
	IntPtr henv = IntPtr.Zero;
	IntPtr hconn = IntPtr.Zero;
	StringBuilder inString = new StringBuilder(SQL_DRIVER_STR);
	StringBuilder outString = new StringBuilder(DEFAULT_RESULT_SIZE);
	short inStringLength = (short) inString.Length;
	short lenNeeded = 0;

	try
	{
		if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
		{
			if (SQL_SUCCESS == SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(IntPtr)SQL_OV_ODBC3,0))
			{
				if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
				{
					if (SQL_NEED_DATA ==  SQLBrowseConnect(hconn, inString, inStringLength, outString, 
								DEFAULT_RESULT_SIZE, out lenNeeded))
					{
						if (DEFAULT_RESULT_SIZE < lenNeeded)
						{
							outString.Capacity = lenNeeded;
							if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString, 
								lenNeeded,out lenNeeded))
							{
								throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
							}	
						}
						txt = outString.ToString();
						int start = txt.IndexOf("{") + 1;
						int len = txt.IndexOf("}") - start;
						if ((start > 0) && (len > 0))
						{
							txt = txt.Substring(start,len);
						}
						else
						{
							txt = string.Empty;
						}
					}						
				}
			}
		}
	}
	catch (Exception)
	{
		//Throw away any error if we are not in debug mode
		txt = string.Empty;
	}
	finally
	{
		if (hconn != IntPtr.Zero)
		{
			SQLFreeHandle(SQL_HANDLE_DBC,hconn);
		}
		if (henv != IntPtr.Zero)
		{
			SQLFreeHandle(SQL_HANDLE_ENV,hconn);
		}
	}
	
	if (txt.Length > 0)
	{
		retval = txt.Split(",".ToCharArray());
	}

	return retval;
}

AnswerRe: how to get sqlserver names in local net Pin
Heath Stewart30-Jun-04 6:56
protectorHeath Stewart30-Jun-04 6:56 
QuestionHow to implement Pin
John L. DeVito29-Jun-04 22:00
professionalJohn L. DeVito29-Jun-04 22:00 
AnswerRe: How to implement Pin
Colin Angus Mackay29-Jun-04 23:14
Colin Angus Mackay29-Jun-04 23:14 
GeneralRe: How to implement Pin
misterbear30-Jun-04 0:55
misterbear30-Jun-04 0:55 
GeneralRe: How to implement Pin
John L. DeVito30-Jun-04 8:17
professionalJohn L. DeVito30-Jun-04 8:17 
GeneralRe: How to implement Pin
Colin Angus Mackay30-Jun-04 8:56
Colin Angus Mackay30-Jun-04 8:56 
GeneralRe: How to implement Pin
John L. DeVito30-Jun-04 13:27
professionalJohn L. DeVito30-Jun-04 13:27 
AnswerRe: How to implement Pin
Werdna30-Jun-04 5:46
Werdna30-Jun-04 5:46 
GeneralRe: How to implement Pin
Werdna30-Jun-04 5:47
Werdna30-Jun-04 5:47 
GeneralCollection class with different class members Pin
pxp29-Jun-04 21:31
pxp29-Jun-04 21:31 
GeneralRe: Collection class with different class members Pin
Rakker7129-Jun-04 23:07
Rakker7129-Jun-04 23:07 
GeneralRe: Collection class with different class members Pin
pxp30-Jun-04 5:05
pxp30-Jun-04 5:05 
GeneralRe: Collection class with different class members Pin
Heath Stewart30-Jun-04 5:56
protectorHeath Stewart30-Jun-04 5:56 
GeneralRe: Collection class with different class members Pin
pxp30-Jun-04 7:32
pxp30-Jun-04 7:32 
GeneralRe: Collection class with different class members Pin
mav.northwind30-Jun-04 8:31
mav.northwind30-Jun-04 8:31 
GeneralRe: Collection class with different class members Pin
pxp30-Jun-04 23:41
pxp30-Jun-04 23:41 
GeneralRe: Collection class with different class members Pin
mav.northwind1-Jul-04 0:29
mav.northwind1-Jul-04 0:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.