Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating ODBC connection through code but it gives me the above error.Below is my code:
VB
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


VB
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

1 solution

VB
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..
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900