By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

VB6 : Create DSN Programatically

neo008
P: 85
Hi all,

Can somebody help me about creation of Data Source Name (DSN) programatically.

I'm using ADO control for connections. MS-Access as database

Thanks

-NEO
Dec 4 '07 #1
Share this Question
Share on Google+
1 Reply


debasisdas
Expert 5K+
P: 8,127
try to use this

1. add the required ODBC library reference from Project ---> References
2. add 2 listboxes,1 textbox and 1 command button on the form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim ds As New ODBCTool.Dsn
  3. If ls.ListIndex <> -1 Then
  4. If Len(Trim(Text1.Text)) = 0 Then
  5. MsgBox "Enter the name of dns"
  6. End If
  7. tt = ds.CreateDSN(Text1.Text, ls.List(ls.ListIndex), "orcl", "", "debasis", "debasis", "", False, "")
  8. Else
  9. MsgBox "Choose the Driver ..."
  10. End If
  11. End Sub
  12.  
  13. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  14. If KeyCode = 116 Then
  15. Dim ds As New ODBCTool.Dsn
  16. Dim List1() As String
  17. tt = ds.GetOdbcDriverList(List1)
  18. ls1.Clear
  19. tt = ds.GetDataSourceList(List1)
  20. For I = 0 To UBound(List1) - 1
  21. ls1.AddItem List1(I)
  22. Next
  23. ls1.Refresh
  24. End If
  25. End Sub
  26.  
  27.  
  28. Private Sub Form_Load()
  29. Dim ds As New ODBCTool.Dsn
  30. Dim List1() As String
  31. tt = ds.GetOdbcDriverList(List1)
  32.  
  33. For I = 0 To UBound(List1) - 1
  34. ls.AddItem List1(I)
  35. Next
  36.  
  37. tt = ds.GetDataSourceList(List1)
  38. For I = 0 To UBound(List1) - 1
  39. ls1.AddItem List1(I)
  40. Next
  41.  
  42. Command1.Enabled = ls.ListIndex <> -1 And Len(Trim(Text1.Text)) > 0
  43. End Sub
  44.  
  45. Private Sub Text1_Change()
  46. Command1.Enabled = ls.ListIndex <> -1 And Len(Trim(Text1.Text)) > 0
  47. End Sub
  48.  
  49.  
Jan 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.