Creating database DSNs

Just starting out? Need help? Post your questions and find answers here.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Creating database DSNs

Post 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!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net