CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2001
    Location
    PA
    Posts
    150

    How to create ODBC?

    Hello,

    What are the steps to create an ODBC connection to Access database?

    Could someone please list for me the steps. I would like to create an ODBC connection to reuse it in my applications.

    Thank you very much in advance.

    Thanks
    Hisham
    Thank You, Hisham

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How to create ODBC?

    Dim Cnn As ADODB.Connection
    Dim strConnect As String

    Set Cnn = New ADODB.Connection

    'Substitute your own User IDs, Password, Data Source, and System
    'database in the connection string below
    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Password=MyPassword;User ID=Administrator;" & _
    "Data Source=C:\AccessDBs\DB1.mdb;" & _
    "Persist Security Info=True;" & _
    "Jet OLEDB:System database=C:\AccessDBs\system.mdw"

    With Cnn
    .CursorLocation = adUseClient
    .Open strConnect
    End With

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Aug 2001
    Location
    PA
    Posts
    150

    Re: How to create ODBC?

    Iuri,

    Thank you for your response. But, is there a way to configure the ODBC prior to everything and us the name of the ODBC to connect. I thought I have seen something like that. They go to start menu>settings>control panel>data sources(ODBC)

    Have you done something like that?

    Thanks
    Hisham
    Thank You, Hisham

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How to create ODBC?

    In control panel-> ODBC you have to create Data Source Name (DSN) and then you can open database

    Set MyDB = Workspaces(0).OpenDatabase("DSN=MyDsN")

    I would not recommend this because you have to install DSN on every PC where you install your program

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: How to create ODBC?

    I found the piece of code for you with DSN

    sConn = "ODBC;DSN=MyDSN;uid=;pwd=;"'doesn't work
    'Open Connection Object
    Set cn = New ADODB.Connection
    cn.ConnectionString = sConn
    cn.Open


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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