Hi guys,

I want ur advices on DB connections.

I usually use System DSN or File DSN to make my connections.

and they are quite useful,flexible
but i am facing the problem of when a user moves his databases, the connection is no longer valid.

some users for example want to move the database outside the folder program so the app.path
wouldn't work sometimes.

So is there any "user Proof" method of creating DB connections.

What do u usually use to connect? and why?

I was thinking of something like a link that would point to the actual database,no matter where it is.

To make myself clear.
I created a notepad file, i created a shortcut for it.
i changed the location of the notepad file, the shortcut is still valid

can i link my DB connection to a .lnk ?

any help guys ?
1st let me warn you that I have no experience with what you're talking about (exept playing around with DSN a couple of times). But here's my feedback (drumroll please...)

Ok first if you're talking about applications, i believe the correct way to use a db in an application is embedding it in the executable and storing the db in the application folder (program files\app name) ir it is user-independant (ya3neh it's the same db for all users) or user folder (document and settings\user name) if it is user dependant.

I believe the correct way to do it for a user-dependant database is put it in
documents and settings\user name\application data\name of the app
or
documents and settings\user name\local settings\application data\name of the app
i dont see why the user should be playing around with these folders. First they are hidden, and then if he renames these folders he'll be changing the settings of all application that he has installed, including your database app.

If the database is not user dependant you can also try to store it in a folder such as windows\system32 or somewhere in the "all users" or "system users" document folders

also keep looking into links maybe it works

You can have tell the system to lock the database file. Users cannot move/delete/rename locked file. I believe there's a windows system call that is used to locks files. As an example, if you have winamp for example, winamp will lock the mp3 file that it is currently playing. If you want to keep the file locked all the time I think you'll have to lock it at every startup, coz i believe that file locks are removed when you reboot (I'm not 100% sure)
There is no "user proof" method if you're using a file-based db. Best you can do is prevent the user of modifying the location of the db file by any means, or at least add a "specify database file" option in the program which will let the user browse for the db file, and will also allow him to use several db files and switch between them when he wants (refer to rolf's post). I personally don't use any DSN method, my connection parameters are always saved and updated in the registry.
That'll be 20$, thank you :)
That'll be 20$, thank you
20 $ to tell me the registry stuff...umm.. 10$ or i google :P
just kidding

if i find the user-proof method, i will let u know :D
have couple of thoughts in my mind, but testing them now :D
5 months later
I think I found something close to user - proof Method :D
To make myself clear.
I created a notepad file, i created a shortcut for it.
i changed the location of the notepad file, the shortcut is still valid
can i link my DB connection to a .lnk ?

Well today i was working on something really different.. i forgot about this
then i donno why it came into my code
you have to create a shortcut in ur app.path folder to your database file
then u will be free to move ur database anywhere , the shortcut will always point to the correct database path
then u read the database from the shortcut.
this code does the reading :D from shortcut to location
‘Add reference to Microsoft Shell Controls and Automation and add a button to a form.
   Dim shl as Shell, file as FolderItem, fld as Folder
   Dim lnk as ShellLinkObject, i as Long, folderPath as string
    
   set shl = new Shell
   'you can use an input box to get the folder path or app.path as said above 
   folderPath = app.path & "\"
   set fld = shl.NameSpace(folderPath)
   'to use browser remove the comment from the next line
' set fld = shl.BrowseForFolder(me.hWnd, "Select Folder that has shortcut file", 0, ssfDESKTOP)
' to use a fixed shortcut name remove the next line
' ShortcutName = "Mydb.lnk"
   ShortcutName = InputBox("Enter shortcut name with extention .lnk", "Shortcut name")

   If Not Right(ShortcutName, 4) = ".lnk" then
     ShortcutName = ShortcutName & ".lnk"
   End If
   on error resume next
   set file = fld.Items.Item(ShortcutName)
   If Err <> 0 then
      MsgBox ShortcutName & " is inaccessable!", vbCritical
      Err.Clear
      GoTo exit_sub
   else
      If file.IsLink then
          set lnk = file.GetLink
         ' redirect.. do the work u want. set the con properties
          MsgBox "Name: " & file.Name & vbCrLf & _
          "Description: " & lnk.Description & vbCrLf & _
          "Path: " & lnk.Path & vbCrLf & _
          "WorkingDirectory: " & lnk.WorkingDirectory & vbCrLf, vbInformation
      else
         MsgBox ShortcutName & " is not a shortcut!", vbInformation
      End If
   End If
exit_sub:
   set lnk = nothing
   set file = nothing
   set fld = nothing
   set shl = nothing
End Sub
that will be for free .. no 20$ required :P
il code baddo tizbit..bass ano.. that is how it can be done
Cool but I dont get the point of automatically tracking the database file!
i dont see why users would wanna change the database location :S
i'm sure there is a much more elegant way of doing it tho the workaround is nice :P
gona see if i can find a better way
hehe users change the database location cuz they are end users ..because they can
sometimes they need to back up ormove their data ..and others still working on the system..
maybe this can help while working on a network
there is a hundred million reason :P
Cool but I dont get the point of automatically tracking the database file!
well this prevents ur application min ano tif2a3 or getting error..or users manipulating several database files
w preventing fraud w heik ossas

halla2 this was a way.. u can always store ur database location in a text file..but if u change the database location , the path is no longer valid

yalla hope u find something kewl :D
I am Open minded even for the weirdest suggestions :P