Page 1 of 1

How to open database?

Posted: Thu Jun 09, 2005 10:19 pm
by Joakim Christiansen
I can open my database with: OpenDatabaseRequester()
But not with: OpenDatabase(0,"WTF should I write here?","","")
It's a mdb database I made with Access and it's stored in the program path...

Posted: Fri Jun 10, 2005 9:46 am
by Pantcho!!
I am also intrested in this, how to load MDB file and ADD/EDIT/DELETE and most important Search.

thank you.

Posted: Fri Jun 10, 2005 11:02 am
by Tranquil
To connect to a database you need an existing ODBC Connection to your database.

Rings (I thought it was rings, sorry if not!) posted two small procedures here to create an ODBC connection within your code.

Code: Select all


#ODBC_ADD_DSN = 1          ; Add Data source
#ODBC_CONFIG_DSN = 2     ; Configure (edit) Data source
#ODBC_REMOVE_DSN = 3    ; Remove Data source

Procedure MakeConnection(Driver.s,strAttributes.s)
  result=OpenLibrary(1,"ODBCCP32.DLL")
  If result 
    lpszDriver.s=Driver
    ; MessageRequester("Info",strAttributes,0)
    *MyMemory=AllocateMemory(Len(strAttributes))
    CopyMemory(@strAttributes,*MyMemory,Len(strAttributes))
    For l=1 To Len(strAttributes )
      If PeekB(*MyMemory +l-1)=Asc(";")
        PokeB(*MyMemory +l-1,0)
      EndIf
    Next l 
    result = CallFunction(1, "SQLConfigDataSource",  0,#ODBC_ADD_DSN,lpszDriver.s,*MyMemory ) 
    FreeMemory(*MyMemory)
    CloseLibrary(1)
    If result
      ProcedureReturn 1
    EndIf
  EndIf
EndProcedure


Procedure DeleteConnection(Driver.s,DSN.s)
  result=OpenLibrary(1,"ODBCCP32.DLL")
  If result 
    lpszDriver.s=Driver
    strAttributes.s = "DSN="+DSN
    result = CallFunction(1, "SQLConfigDataSource",  0,#ODBC_REMOVE_DSN,lpszDriver.s,strAttributes ) 
    CloseLibrary(1)
    If result
      ProcedureReturn 1;MessageRequester("Info","DSN Delete",0)
    EndIf
  EndIf
EndProcedure
For eg this creates an ODBC connection:

result=MakeConnection("Microsoft Access Driver (*.mdb)","Server=Your Server Name hier; Description=some text here;DSN=YourDatabaseName;DBQ=c:\accessdatabase.mdb;UID=;PWD=;")

If everything goes right you can now use OpenDatabase(0,"YourDatabaseName").

Mike

Re: How to open database?

Posted: Fri Jun 10, 2005 3:09 pm
by Paul
Joakim Christiansen wrote:I can open my database with: OpenDatabaseRequester()
But not with: OpenDatabase(0,"WTF should I write here?","","")
It's a mdb database I made with Access and it's stored in the program path...
You can try downloading the MDB_Lib from http://www.pureproject.net (ASM lib section)
It makes creating and connecting to MDB and mySQL databases a breeze and the sample code will get you started very quickly. :)

Posted: Fri Jun 10, 2005 6:21 pm
by Joakim Christiansen
Thanks Tranquil and Paul :)

Posted: Fri Jun 10, 2005 8:23 pm
by Pantcho!!
I am using almost all Paul's great ASM libs.
the MDB lib is great Paul, but can you post some more examples please?

we sure do miss a database tips and tricks and tips and tricks with your easy to understand lib will be very helpful :) .

thank you.

Posted: Thu Jun 16, 2005 9:21 am
by nrasool
Hi there

Look at Paul Example on the following thread - very useful :)
viewtopic.php?t=13831

Kind Regardss