CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 1999
    Location
    USA
    Posts
    101

    How to get DSN less connections

    I am using ADO's to connect to Access database. I assume in that case, it runs without DSN at the client site.

    Thanks



  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: How to get DSN less connections

    You don't have to use a DSN-less connection with ADO just because you're using an Access database. Although, it would be better not to use one (less hassle to set up app on new machine). To use a DSN-less connection with ado and an Access database, the following should work:


    Dim cn as ADODB.Connection
    Dim rs as ADODB.Recordset

    set cn = new ADODB.Connection
    cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};"
    cn.ConnectionString = cn.ConnectionString & "DBQ=" & App.Path & "\accessfile.mdb;"

    cn.Open





    You will of course have to provide the correct path to the .mdb file after the 'DQB' switch.

    This should get you going.

    Good luck.

    John


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Guest

    what is the difference?

    what is the difference between DSN connection and DSNless connection?
    Explain


  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: what is the difference?

    DSN stands for DataSource Name. These are setup in the control panel under ODBC32. There are system DSNs and user DSNs on a machine. To use a DSN in your connectionstring you would specify the DSN, UID and PWD instead of the above way. Connecting to a database with a DSN uses the ODBC protocol, without - uses the OLE DB protocol (when used with ADO). To use a DSN with an Access database, you add a new entry in the ODBC section of the control and point it to an Access database. You can name this "pointer" anything you want. For example, I have an .mdb in my C:\dev\vb directory that i want to connect to. I could add a DSN for this database, call it MyDSN and use it in a connection string like this:

    cn.connectionstring = "DSN=MyDSN;UID=admin;PWD=;"
    cn.open

    If the DSN is set up correctly, the connection will be opened.

    One of the bad things about using DSN's in production apps, is every machine that will use your app will have to have a DSN setup on that local machine. This leads to the nice thing about not using DSNs, you can move your app anywhere and as long as your code is supplying the path to the .mdb relatively (ie. app.path & "..\..\path\path2\filename.mdb") it will run.

    Hope this helps,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

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