[quoted text, click to view] On Fri, 9 Jan 2004 08:31:51 -0800, "Robb Gilmore" <rgilmore@indsci.com> wrote:
¤ Is there a function somewhere in the .NET framework that
¤ will return me a list of the DSN's defined on the machine
¤ where the app is running?
See if the following works for you:
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv As Integer, ByVal
fDirection As Short, ByVal szDSN As String, ByVal cbDSNMax As Short, ByRef pcbDSN As Short, ByVal
szDescription As String, ByVal cbDescriptionMax As Short, ByRef pcbDescription As Short) As Short
Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (ByRef env As Integer) As Short
Const SQL_SUCCESS As Integer = 0
Const SQL_FETCH_NEXT As Integer = 1
Public Sub FetchDSNs()
Dim ReturnValue As Short
Dim DSNName As String
Dim DriverName As String
Dim DSNNameLen As Short
Dim DriverNameLen As Short
Dim SQLEnv As Integer 'handle to the environment
If SQLAllocEnv(SQLEnv) <> -1 Then
Do Until ReturnValue <> SQL_SUCCESS
DSNName = Space(1024)
DriverName = Space(1024)
ReturnValue = SQLDataSources(SQLEnv, SQL_FETCH_NEXT, DSNName, 1024, DSNNameLen,
DriverName, 1024, DriverNameLen)
DSNName = Left(DSNName, DSNNameLen)
DriverName = Left(DriverName, DriverNameLen)
If DSNName <> Space(DSNNameLen) Then
System.Diagnostics.Debug.WriteLine(DSNName)
System.Diagnostics.Debug.WriteLine(DriverName)
End If
Loop
End If
End Sub
Paul ~~~ pclement@ameritech.net