Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

creating a DSN via VB

Posted on 2004-10-13
5
Medium Priority
?
185 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 70

Accepted Solution

by:
Éric Moreau earned 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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

927 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