Solved

creating a DSN via VB

Posted on 2004-10-13
5
176 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now