Page 1 of 1

Creating database DSNs

Posted: Wed Jul 23, 2003 4:50 am
by Karbon
I found this the other day in an app I wrote some months ago. I didn't write it but I can't remember who did! Still, thought I would share..

Creating a DSN for Access on the fly :

Code: Select all

Procedure.l database_command(command.s)
  
  cmd.l = AllocateMemory(9,Len(command))
  
  For tmp=0 To Len(command)-1
  
    asc=PeekB(@command+tmp)
  
    If asc=59
  
      PokeB(cmd+tmp,0)
  
      Else
  
      PokeB(cmd+tmp,asc)
  
    EndIf
  
  Next   
  
  If OpenLibrary(9,"ODBCCP32.DLL")  
  
    SQLConfigDataSource = IsFunction(9,"SQLConfigDataSource")
  
    Result = CallFunctionFast(SQLConfigDataSource,0,1,"Microsoft Access Driver (*.mdb)",cmd) 
  
    CloseLibrary(9)
  
  EndIf  
  
  FreeMemory(9)
  
  ProcedureReturn Result

EndProcedure
Use it like this : (replacing the my_* stuff with the right stuff of course!)

Code: Select all

database_command("Server=RMServer;Description=my_db;DSN=my_db;DBQ=c:\my_db.mdb"+";UID=my_username;PWD=my_password;")
Hope it helps someone!