?
Solved

"ODBC DSN List in VB"

Posted on 2003-03-23
2
Medium Priority
?
467 Views
Last Modified: 2008-02-20
hello,

i want dsn (user dsn, file dsn, system dsn) list value in local pc in Visual Basic 6.0.
It is possible through ODBC Api then which Api is applicable for that.
Or any otherway it is possible to retrive list of dsn through vb.

thankx.
0
Comment
Question by:NishaSangani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:Sankar_V
ID: 8193324
Hi !

Just try this code!

this may not be the right one u want!

But u can get an idea with this!

i got this code from vbcode.com!


Private Declare Function SQLDataSources% Lib "ODBC32.DLL" (ByVal henv&, ByVal fdir%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDesc$, ByVal cbDescMax%, pcbDesc%)
Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS As Long = 0
Const SQL_FETCH_NEXT As Long = 1

Public Sub GetDSNs(Box As ComboBox)
Dim i As Integer
Dim sDSNItem As String * 1024
Dim sDRVItem As String * 1024
Dim sDSN As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long     'handle to the environment

   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 = Left(sDSNItem, iDSNLen)
         If sDSN <> Space(iDSNLen) Then
            Box.AddItem sDSN
         End If
      Loop
      Box.ListIndex = 0
   End If
End Sub

Private Sub Form_Load()
   Call GetDSNs(Combo1)
End Sub
0
 

Accepted Solution

by:
shahkalpesh earned 1000 total points
ID: 8193765
Hi,

Try using one of the template form in VB. Using Add Form - it will show you the template form available such as splash screen/about. There is such a template form for ODBC login

You can use the source code, which actually fills the combobox with the DSNs on your system

Do write back if it helps you
Kalpesh
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question