Solved

creating a DSN via VB

Posted on 2004-10-13
5
177 Views
Last Modified: 2010-05-02
Folks
I have a VB app that refers to a DSN on my machine.
Is there a smart way of automating /creating this dsn on other peoples machines so I can pass them on my vb app.
Can I build something into the VB package to create this ?

Any help appreciated
Paul
 
0
Comment
Question by:skintpaul
  • 2
5 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 75 total points
ID: 12300175
0
 
LVL 4

Expert Comment

by:AjithJose
ID: 12300582
Use these code sinppets to create/delete DSN from VB


      Option Explicit

      'Constant Declaration
      Private Const ODBC_ADD_DSN = 1        ' Add data source
      Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
      Private Const ODBC_REMOVE_DSN = 3     ' Remove data source
      Private Const vbAPINull As Long = 0&  ' NULL Pointer


          Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
          (ByVal hwndParent As Long, ByVal fRequest As Long, _
          ByVal lpszDriver As String, ByVal lpszAttributes As String) _
          As Long
                         

' Create DSN sample


     Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String

      'Set the driver to SQL Server because it is most common.
      strDriver = "SQL Server"
      'Set the attributes delimited by null.
      'See driver documentation for a complete
      'list of supported attributes.
      strAttributes = "SERVER=SomeServer" & Chr$(0)
      strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
      strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)
      strAttributes = strAttributes & "DATABASE=pubs" & Chr$(0)
      'To show dialog, use Form1.Hwnd instead of vbAPINull.
      intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
      strDriver, strAttributes)

      If intRet Then
          MsgBox "DSN Created"
      Else
          MsgBox "Create Failed"
      End If



'Delete DSN Sample

      Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String

      'Set the driver to SQL Server because most common.
      strDriver = "SQL Server"
      'Set the attributes delimited by null.
      'See driver documentation for a complete list of attributes.
      strAttributes = "DSN=DSN_TEMP" & Chr$(0)
      'To show dialog, use Form1.Hwnd instead of vbAPINull.
      intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, _
      strDriver, strAttributes)

      If intRet Then
          MsgBox "DSN Deleted"
      Else
          MsgBox "Delete Failed"
      End If

   

Reference: http://support.microsoft.com/kb/q171146/ 


0
 

Author Comment

by:skintpaul
ID: 12306446
I see by using the above snippets, I can create a dsn that appears under the System DSN tab rather than the User DSN tab. Should I be concerned about that ?
The one I was looking to mimic was created in User DSN.

Also how would I set the verification piece ie.  
How Should SQL Server verify the authenticity of the Login ID
Choices are Windows NT or SQL Server

Thanks
Paul

Ps. I upped the points from 50 to 75
0
 

Author Comment

by:skintpaul
ID: 12319342
Folks
I found the answer to the above 2 issues I mentioned
Thanks
Paul
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now