Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use SQLDataSources( ) in VB.NET?

Status
Not open for further replies.

sjh

Programmer
Oct 29, 2001
263
US
Hi,
Does anybody know how to enumerate system DSNs by calling SQLDataSources( )?

Thanks so much!
Susie
 
What are you trying to do with the data source.. Could you use the SQLDataAdapter, SQLDAtaConnection
 
Hi, I want to use SQLDataSources to find out the driver of the database - whether it's oracle or sql server, etc. I found the code for VB6, but I couldn't make it work in .NET. Please point out what I am doing wrong!

Thanks!
Susie
____________________________
Here's the VB6 code that I tried to use.

Private Declare Ansi Function SQLDataSources Lib "odbc32.dll" _
(ByVal hEnv As Long, ByVal fDirection As Integer, _
ByVal szDSN As String, ByVal cbDSNMax As Integer, ByVal pcbDSN As Integer, _
ByVal szDescription As String, ByVal cbDescriptionMax As Integer, _
ByVal pcbDescription As Integer) As Integer

Private Declare Function SQLAllocEnv Lib "odbc32.dll" (ByVal phenv As Long) As Integer
Private Declare Function SQLFreeEnv Lib "odbc32.dll" (ByVal hEnv As Long) As Integer
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_FETCH_NEXT As Long = 1
Private Const SQL_FETCH_FIRST_SYSTEM As Long = 32

Sub GetDSNsAndDrivers()
Dim i As Integer
Dim sDSNItem As String = New String(" ", 1024)
Dim sDRVItem As String = New String(" ", 1024)
Dim sDSN As String
Dim sDRV As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long
Dim strResult As String

On Error Resume Next
If SQLAllocEnv(lHenv) <> -1 Then
Do Until i <> SQL_SUCCESS
sDSNItem = Space(1024)
sDRVItem = Space(1024)
i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
sDSN = sDSNItem.Substring(0, iDSNLen)
sDRV = sDRVItem.Substring(0, iDRVLen)
If sDSN <> Space(iDSNLen) Then
strResult = strResult & sDSN & " (" & sDRV & ")" & vbNewLine
End If
Loop
End If
MsgBox(strResult)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top