Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than odbc32, prefix the name with the module name and a period.
SQLDataSources (odbc32)
.
C# Signature:
/// <summary>
/// SQLDataSources returns information about a data source. This function is implemented solely by the Driver Manager.
/// </summary>
/// <param name="EnvironmentHandle">[Input] Environment handle.</param>
/// <param name="Direction">[Input] Determines which data source the Driver Manager returns information on.</param>
/// <param name="ServerName">[Output] Pointer to a buffer in which to return the data source name.</param>
/// <param name="BufferLength1">[Input] Length of the *ServerName buffer, in characters; this does not need to be longer than SQL_MAX_DSN_LENGTH plus the null-termination character.</param>
/// <param name="NameLength1Ptr">[Output] Pointer to a buffer in which to return the total number of bytes (excluding the null-termination byte)
/// available to return in *ServerName. If the number of bytes available to return is greater than or equal to BufferLength1, the data
/// source name in *ServerName is truncated to BufferLength1 minus the length of a null-termination character. </param>
/// <param name="Description">[Output] Pointer to a buffer in which to return the description of the driver associated with the data source.
/// For example, dBASE or SQL Server.</param>
/// <param name="BufferLength2">[Input] Length in characters of the *Description buffer.</param>
/// <param name="NameLength2Ptr">[Output] Pointer to a buffer in which to return the total number of bytes (excluding the null-termination
/// byte) available to return in *Description. If the number of bytes available to return is greater than or equal to BufferLength2,
/// the driver description in *Description is truncated to BufferLength2 minus the length of a null-termination character.</param>
/// <returns>SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_NO_DATA, SQL_ERROR, or SQL_INVALID_HANDLE.</returns>
[DllImport("odbc32.dll", CharSet=CharSet.Ansi)]
static extern short SQLDataSources(IntPtr EnvironmentHandle, short Direction,
StringBuilder ServerName, short BufferLength1, ref short NameLength1Ptr,
StringBuilder Description, short BufferLength2, ref short NameLength2Ptr);
VB Signature:
Declare Function SQLDataSources _
Lib "odbc32.dll" _
( _
ByVal EnvironmentHandle As Integer, _
ByVal Direction As Short, _
ByVal ServerName As String, _
ByVal BufferLength1 As Short, _
ByRef NameLength1Ptr As Short, _
ByVal Description As String, _
ByVal BufferLength2 As Short, _
ByRef NameLength2Ptr As Short _
) _
As Short
User-Defined Types:
None.
Notes:
MSDN Documentation was sourced for the precise parameter definitions and return values.
Depending on the value of Direction, you may access System DSN, User DSN or both. Since the same DSN name may be used in User and System DSN, watch out for possible duplicate values.
Sample Code:
One use of this function is to populate a combobox with available DSN's in a login screen...
[DllImport("odbc32.dll", CharSet=CharSet.Ansi)]
public static extern short SQLDataSources(IntPtr EnvironmentHandle, short Direction,
StringBuilder ServerName, short BufferLength1, ref short NameLength1Ptr,
StringBuilder Description, short BufferLength2, ref short NameLength2Ptr);
[DllImport("ODBC32.DLL", CharSet=CharSet.Auto)]
public static extern short SQLAllocEnv(out IntPtr env);
private void GetODBC()
{
const int SQL_SUCCESS = 0;
const int SQL_FETCH_NEXT = 1;
int i = 0;
StringBuilder sDSNItem;
StringBuilder sDRVItem;
string sDSN = string.Empty;
string sDRV = string.Empty;
short iDSNLen = 0;
short iDRVLen = 0;
IntPtr lHenv ; // 'handle to the environment
//get the DSNs
if ( NativeWIN32.SQLAllocEnv(out lHenv) != -1)
{
do
{
sDSNItem = new StringBuilder(1024);
sDRVItem = new StringBuilder(1024);
i = NativeWIN32.SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, ref iDSNLen, sDRVItem, 1024, ref iDRVLen);
if (i == SQL_SUCCESS)
{
sDSN = sDSNItem.ToString().Substring(0, iDSNLen);
sDRV = sDRVItem.ToString().Substring(0, iDRVLen);
}
}
while(i == SQL_SUCCESS);
}
}
Alternative Managed API:
Do you know one? Please contribute it!
SQLAllocHandle allocates an environment, connection, statement, or descriptor handle.
4/23/2007 5:42:19 AM - dado-89.216.176.216
SQLAllocHandle allocates an environment, connection, statement, or descriptor handle.
4/23/2007 5:42:19 AM - dado-89.216.176.216
SQLAllocEnv allocates memory for an environment handle and initializes the ODBC call level interface for use by an application. An application must call SQLAllocEnv prior to calling any other ODBC function.
3/16/2007 8:06:17 AM - Steve Waggoner-65.223.32.12
SQLAllocHandle allocates an environment, connection, statement, or descriptor handle.
4/23/2007 5:42:19 AM - dado-89.216.176.216
SQLSetEnvAttr sets attributes that govern aspects of environments.
4/19/2013 1:13:49 PM - -72.38.243.254
Provide access to configured user and system Data Source Names (DSN) and installed ODBC drivers
3/16/2007 8:06:25 AM - -65.223.205.130
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).