Solved

creating a DSN via VB

Posted on 2004-10-13
5
181 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
[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
5 Comments
 
LVL 70

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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