Creating ODBC DSN programmatically with VB.Net

I have a VB.Net app that I wrote three years ago (2008) which creates ODBC entries for SQL Server 2000 and SQL Server 2005.  The original source found at

The apps runs fine on my computer, but when I run it on our test machine (Windows XP) or a users machine (Windows 7) it crashes.  Some users will not have SQL Native Client available even manually creating the ODBC DSN.

The error message received is:
Unable to find an entry point name 'SQLConfigDataSource32bit" in DLL 'ODBCCP32.DLL'
Below is the "important" code which is used to create ODBC entry.

I am so out of my league here, so be gentle and understanding! :) Thanks!

Private Declare Function SQLConfigDataSource32bit Lib "ODBCCP32.DLL" _
     (ByVal hwndParent As Integer, ByVal ByValfRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer

  Private Const vbAPINull As Integer = 0 ' NULL Pointer
  Private Const ODBC_ADD_DSN As Short = 1 ' Add data source

  Friend DriverName As String


Private Sub btnCreateDSN_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnCreateDSN.Click

    If Len(Me.txtUsername.Text) = 0 Then
      MsgBox("Username cannot be blank")
      Exit Sub
    End If

    Dim intRet As Integer
    Dim Attributes As String

    'Set the attributes delimited by null.
    'See driver documentation for a complete
    'list of supported attributes.
    Attributes = "SERVER=" & Me.txtServer.Text & Chr(0)
    Attributes = Attributes & "DATABASE=" & Me.txtDBName.Text & Chr(0)
    Attributes = Attributes & "DESCRIPTION=" & Me.txtDesc.Text & Chr(0)
    Attributes = Attributes & "DSN=" & Me.txtDSN.Text & Chr(0)
    Attributes = Attributes & "TRUSTED_CONNECTION=YES" & Chr(0)

    'To show dialog, use Form1.Hwnd instead of vbAPINull.
    intRet = SQLConfigDataSource32bit(vbAPINull, ODBC_ADD_DSN, DriverName, Attributes)

    If intRet <> 0 Then
      MsgBox("DSN Created")
      MsgBox("Create Failed")
    End If

  End Sub 'Private Sub btnCreateDSN_Click

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CMI_ITAuthor Commented:
No, I didn't see this.  It didn't come up in my Google search.  I will take a look at it (it looks promising! :) ).
CMI_ITAuthor Commented:
I have looked at your code/app.  You are also using the 'ODBCCP32.DLL'.  Other than the order of the attributes the proccess is the same (see my code above).

If 'ODBCCP32.DLL' is a Windows DLL and is present on the target machine why am I getting the error:
Unable to find an entry point name 'SQLConfigDataSource32bit" in DLL 'ODBCCP32.DLL'
CMI_ITAuthor Commented:
I have fixed my own problem.  It was the "32bit" that had at some point been added to the 'SQLConfigDataSource'.  Removed it and now it runs just fine.

I am going to award the points to emoreau because his solution is more dynamic and has more features, which I plan on implementing.  If I hadn't looked at his solution again and wrote my last comment then I wouldn't have found the problem.  Thanks, emoreau!
CMI_ITAuthor Commented:
I have fixed my own problem.  It was the "32bit" that had at some point been added to the 'SQLConfigDataSource'.  Removed it and now it runs just fine.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.