CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ODBC Connection

  1. #1
    Join Date
    Jun 1999
    Posts
    4

    ODBC Connection

    I need to know where is the error in following code for MS ACCESS connection through ODBC. Can I have the corrected code ?



    private Sub Form_Load()
    Dim PrivDb as Database
    set PrivDb = OpenDatabase("", false, false, "ODBC;DSN=Hospital;UID=xxx;Pwd=xxx;")
    End Sub




    ODBC setting :
    ODBC Driver = Microsoft Access Driver (*.mdb)
    DSN = Hospital
    Database = C:\Hospital
    UID = xxx
    PWD = xxx

    Note : The above code is working if i change the driver to Sql Server

    Thanks.



  2. #2
    Join Date
    Nov 1999
    Posts
    3

    Re: ODBC Connection

    Try to Change UID= to User ID= & PWD= to Pasword=


  3. #3
    Join Date
    Nov 1999
    Posts
    9

    Re: ODBC Connection

    There is a error in the openrecordset statement... iF you are using ADO then you just have to pass the database name and the dsn name
    e.g.

    dim objectname as new Connection
    dim strconnect as string

    strconnect = "Database=Hospital;dsn=dsnHospital"
    objectname.open (strconnect)


  4. #4
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: ODBC Connection

    sunitha,
    I used following with RDO.

    Global Cn as rdoConnection
    public Sub Main()
    Dim Cnct as string
    Cnct$ = "DSN=MS ACCESS;UID=santulan;PWD=beluz1;DATABASE=EOC.mdb;"
    set Cn = rdoEnvironments(0).OpenConnection("", rdDriverNoPrompt, false, Cnct$)




    This works :-)>.
    In your project reference add RDO object before trying it.



    Santulan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured