473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Enumerate List of ODBC DSNs

I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
have seen how to do this but I can't seem to dag it. Can anyone help?

Thanks,
Bernie
Jul 8 '08 #1
3 3110
JB
On 8 Jul, 00:59, "Bernie Hunt" <bh...@optonline.netwrote:
I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
have seen how to do this but I can't seem to dag it. Can anyone help?

Thanks,
Bernie
Voilà...

'API to obtain list of ODBC connections
Private Declare Function SQLAllocEnv Lib "ODBC32.DLL" (ByRef env As
Integer) As Short
Private Declare Function SQLFreeHandle Lib "odbc32.dll" (ByVal
handleType As Short, ByVal Handle As Integer) As Short
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal
WindowHandle As Integer, ByVal Direction As Short, ByVal DSNBuffer As
String, ByVal DSNBufferLength As Short, ByRef DSNLength As Short,
ByVal DESCBuffer As String, ByVal DESCBufferLength As Short, ByRef
DESCLength As Short) As Short
Public Shared Sub LoadDSNList(ByVal ComboBoxCtrl As ComboBox)
Const SQL_BUFFER_SIZE As Short = 1024
Const SQL_SUCCESS As Short = 0
Const SQL_SUCCESS_WITH_INFO As Short = 1
Const SQL_FETCH_FIRST As Short = 1
Const SQL_HANDLE_ENV As Integer = 1

Dim env, RetInt As Integer
Dim RetShort As Short = SQL_SUCCESS
Dim BufferDSN, BufferDesc As String
Dim LengthDSN, LengthDesc As Short
Dim DSNName As String

ComboBoxCtrl.Items.Clear()

RetInt = SQLAllocEnv(env)
If (RetInt = SQL_SUCCESS) Or (RetInt = SQL_SUCCESS_WITH_INFO) Then
'Get the DSN names & descriptions
While (RetShort = SQL_SUCCESS) Or (RetShort =
SQL_SUCCESS_WITH_INFO)
BufferDSN = Space(SQL_BUFFER_SIZE)
BufferDesc = Space(SQL_BUFFER_SIZE)
RetShort = SQLDataSources(env, SQL_FETCH_FIRST, BufferDSN,
SQL_BUFFER_SIZE, _
LengthDSN, BufferDesc,
SQL_BUFFER_SIZE, LengthDesc)

DSNName = BufferDSN.Substring(0, LengthDSN)
If (DSNName <Space(LengthDSN)) Then
ComboBoxCtrl.Items.Add(DSNName)
End While

SQLFreeHandle(SQL_HANDLE_ENV, env)
env = Nothing
End If

If (ComboBoxCtrl.Items.Count < 1) Then
ComboBoxCtrl.Items.Add(My.Resources.S_MISC_NO_ODBC _CONNECTIONS_AVAILABLE)
End Sub
Jul 9 '08 #2
JB
On 8 Jul, 00:59, "Bernie Hunt" <bh...@optonline.netwrote:
I'd like to read a list of the ODBC DSNs set up on the computer. I thought I
have seen how to do this but I can't seem to dag it. Can anyone help?

Thanks,
Bernie
I've posted a reply a couple of hours ago and it still doesn't show...
Jul 9 '08 #3
JB
Still not showing...
Jul 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
0
by: Lewt | last post by:
I am aware of the 'hack the registry' approach. This is just not a safe way to accomplish this on a user's PC. I need to do this the right way. Is there anyone -perhaps from Microsoft - out there...
2
by: Karl A Mikesell | last post by:
Using ODBC DSN connection in ASP.net does not work, but same code will execute properly as a Windows application, is this the result of .NET Code Access Security, since user DSNs are registry...
18
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.