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

Thread: DSN free code

  1. #1
    Join Date
    Nov 2003
    Posts
    12

    Question DSN free code

    Hi,

    I have a small application in VB which writes some information onto Microsoft Access database tables. For this to happen, I have created a DSN referring the corresponding .mdb file.

    To run my application on some other machine I need to create a DSN over there. This is going to be a tedious job.

    Can anyone suggest me a method wherein I can access the database tables without the use of a DSN.

    Any help/ideas in this regard would be highly appreciated.

    Regards
    Cufit

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    If you can map drive

    And if you can have your access mdb in a shared folder,
    and if clients may have rights to read wirte there, then you could
    map on each client the folder where the mdb is and use
    a built connection string that might be all te same for each client
    Or you could have a component on server (=machine where
    access is) that retrieve recordsets or write or update or delete,
    and have clients referencing and using that component.
    If mdb is on a machine like win2k or greater, you could take
    advantage of Com+.
    If not, you might have to fight with Dcom, in wich case you
    might prefer the Dns strategy....
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    cufit99,

    You can access the database without the DSN, this is called a DSN-less connection. Below is a sample connection string for Access database using ADO Jet provider.
    Code:
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                  "Data Source=<the mdb path here>"
    Busy

  4. #4
    Join Date
    Nov 2003
    Posts
    12

    Lightbulb

    Hi,

    Thank you both Cimperiali and Thread1.
    My application mostly runs over a private network, so having the mdb file in a shared folder is not feasible.

    So, I tried to use the DSN less connection and it really worked well. Now I'm trying out ways to create an mdb file with the required tables programatically.

    Thank You for your timely help.....


    Regards,
    Cufit

  5. #5
    Join Date
    Mar 2001
    Location
    Romania
    Posts
    71

    DSN free code

    Why don't you try to change DSN from VB? All you have to do is to modify something in registry.

  6. #6
    Join Date
    Apr 2004
    Posts
    5
    Hi
    This thread came in a search I did.
    My problem is after I make the DSN-less connection to the Access Database, I get a recordset with -1 RecordCount.
    Here's the Code:

    Code:
    cnPhase1.Open GetConnectionString(strPhase1DB)
    rsPhase1.LockType = adLockOptimistic
    rsPhase1.ActiveConnection = cnPhase1
    rsPhase1.Source = "Phase1"
    rsPhase1.Open
    ...
    Code:
    Private Function GetConnectionString(filename As String) As String
    GetConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                  "Data Source=" & filename
    End Function
    I don't get any errors, just a -1 as rsPhase1.RecordCount.
    When I open the Database with MS Access, go into the table "Phase1", I see 2 existing records.
    What could be the problem?
    Thanks in advanced.

  7. #7
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646
    use cursorlocation = adUseClient for your connection object before opening it

  8. #8
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    ..and for CursorLocation = adUseServer (default), try to use cursor that supports the bookmarking (method Supports(adBookMark)) - Keyset and Static (adOpenKeyset and adOpenStatic) in the CursorType property of the recordset obj.
    Busy

  9. #9
    Join Date
    Oct 2003
    Posts
    8
    Try MoveLast before RecordCount.

    Code should be also secured with checking BOF and EOF properties.

    aki999

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