Click here to Skip to main content
12,396,461 members (70,288 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
I am creating ODBC connection through code but it gives me the above error.Below is my code:
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

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DsnName As String = "Search1"
        Dim PathDB As String = "E:\Rachna\LocalityDd.mdb"
        Dim UID As String = ""
        Dim PAssWord As String = ""
 
        Const ODBC_ADD_DSN = 1 'Add User DSN
        Dim rl As Long
        Dim Strsetting As String = ""
        Strsetting = Strsetting + "dsn=" & DsnName
        Strsetting = Strsetting + ";" + "DBQ=" & PathDB '& Chr(0) & Strsetting
        Strsetting = Strsetting + ";" + "uid=" & UID '& Chr(0) & Strsetting
        Strsetting = Strsetting + ";" + "pwd=" & PAssWord '& Chr(0) & Strsetting

        rl = SQLConfigDataSource(0&, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", Strsetting)
 
        If rl = 1 Then
            MsgBox("Created ODBC")
        Else
            MsgBox("Error")
        End If
    End Sub

Can any1 please help me to rectify the error??
Thanks in advance.
Posted 17-Dec-12 17:31pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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


Just replaced Long with Int32 and it solved my problem..
  Permalink  
Comments
Devang Vaja 2-Jan-13 7:18am
   
have u got sollution?rachu sorry rachna ji

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100