How to open database?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

How to open database?

Post 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...
I like logic, hence I dislike humans but love computers.
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

I am also intrested in this, how to load MDB file and ADD/EDIT/DELETE and most important Search.

thank you.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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
Tranquil
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: How to open database?

Post 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. :)
Image Image
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Thanks Tranquil and Paul :)
I like logic, hence I dislike humans but love computers.
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post 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.
nrasool
User
User
Posts: 28
Joined: Tue Apr 26, 2005 9:55 am

Post by nrasool »

Hi there

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

Kind Regardss
Post Reply