Page 1 of 1
ODBC/Connection string and use of OCX
Posted: Wed Apr 05, 2006 8:07 pm
by dmb
Hi,
I'm currently using VB6 for my (business) applications and I'm looking for a good alternative. PB looks quite good. I really like the idea of a one-EXE application (remembers me of the good-old DOS days

).
I've browsed through the forum, but still couldn't find a definitive answer to the following two questions:
- Can I use a connection string to connect to a ODBC database.
- Is it possible to add OCX controles to a form (for using the Crystal Reports RDC viewer).
I can't "live" without these two ... I hope it's possible.
Posted: Wed Apr 05, 2006 8:53 pm
by Num3
Yes you can connect to any database via ODBC.
And you can use cristal reports too, but you need to use via DLL.
And no, you can't use OCX in programming with purebasic

Posted: Wed Apr 05, 2006 9:02 pm
by ts-soft
Num3 wrote:
And no, you can't use OCX in programming with purebasic

you can use some ocx, but is complicated!
Posted: Thu Apr 06, 2006 8:36 am
by dmb
Num3 wrote:Yes you can connect to any database via ODBC.
I know that it's possible to connect to a ODBC database, but for my purposes I need to be able to specificy connection properties via a connection string. F.e. information like userid, password, database number and servername is not available in the DSN I use. Besides that I need to be flexible, what means that I don't want to use a seperate DSN for each database number.
I couldn't find a command/parameter in which I could specify the connection string and I found an old post from 2003 in which it's said that this is not possible. But maybe this has been added since then or else in the new 4.0 version.
Posted: Thu Apr 06, 2006 12:22 pm
by jb
dmb wrote:I'm currently using VB6 for my (business) applications and I'm looking for a good alternative. PB looks quite good.
I agree with dmb, DSN-less connections are a much needed feature in PureBasic. Adding this feature would surely attract some current VB users.
I found the following code on PureArea.net written by Rings, bobobo, and Lars. It may be of some help to you.
Code: Select all
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=1513&highlight=
; Author: bobobo (updated for PB3.92+ by Lars)
; Date: 26. June 2003
; MS-SQL ODBC-DSN on the fly with TCP/IP-connection
; tested with MS-SQL-SERVER on W2K-Server and W2K-WS as Client
;Folgender Code geht für MS-SQL DB's
;Erzeugen einer temporären DSN für vorhandene MS-SQL-Datenbanken.
;Das folgende im Code beachten und anpassen..
;;-FOLGENDE ZEILE ANPASSEN
;Create DSN on the fly for ODBC
;
; An example by Siegfried Rings (CodeGuru)
; extended by bobobo
#ODBC_ADD_DSN = 1 ; Add Data source
#ODBC_ADD_SYS_DSN = 4 ; Add SYSTEM Data source
#ODBC_CONFIG_DSN = 2 ; Configure (edit) Data source
#ODBC_REMOVE_DSN = 3 ; Remove Data source
#ODBC_REMOVE_SYS_DSN = 6 ; Remove SYSTEM Data source
#WINDOW=0
#SHOWINFO=101
crlf.s=Chr(13)+Chr(10)
Procedure.s Showinfo(info.s)
crlf.s=Chr(13)+Chr(10)
SetGadgetText( #SHOWINFO,GetGadgetText(#SHOWINFO)+info+crlf)
While WindowEvent():Wend
EndProcedure
Procedure MakeConnection(Driver.s,strAttributes.s)
Result=OpenLibrary(1,"ODBCCP32.DLL")
If Result
lpszDriver.s=Driver
Showinfo(strAttributes)
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_SYS_DSN,lpszDriver.s,MyMemory )
FreeMemory(MyMemory)
CloseLibrary(1)
If Result
ProcedureReturn 1;MessageRequester("Info","DSN Created",0)
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_SYS_DSN,lpszDriver.s,strAttributes )
CloseLibrary(1)
If Result
ProcedureReturn 1;MessageRequester("Info","DSN Delete",0)
EndIf
EndIf
EndProcedure
;-FOLGENDE ZEILE ANPASSEN Addresse
ADDRESS$="127.0.0.1,1433" ; Network address,Port of the SQL Server.
Network$="DBMSSOCN" ; VerbindungsArt
;-FOLGENDE ZEILE ANPASSEN StandardDatenbank
DATABASE$="STANDARDDATENBANK" ;Name of the Default database for the connection
;If Database is not specified, the Default database
;defined For the login is used
DESCRIPTION$="MEINE_DATENBANK_BESCHREIBUNG" ;Description
DRIVER$="SQL Server"
QUERYLOG_ON$="no" ;default no : enables long query-runs
QUERYLOGFILE$="c:\ODBCquery.log" ;Full path and name of the file used to log long-running queries.
QUERYLOGTIME$="1" ;Digit character string specifying the threshold (in milliseconds)
;for logging long-running queries. Any query that does not get a
;response in the time specified is written To the long-running
;query log file.
;-FOLGENDE ZEILE ANPASSEN Name oder ip-Nummer des MS-SQL-SERVERS
SERVER$="MEIN-MS-SQL-SERVER" ;Name of a server running SQL Server on the network
STATSLOG_ON$="no" ;Enables driver performance logging
STATSLOGFILE$="c:\ODBCPerformance.log" ;Full pth of Log Driver Performance
;FOR DB-LogOn
;-FOLGENDE ZEILE ANPASSEN (funktional nicht wichtig)
DSN$="MEINE_DB_VERBINDUNG" ; dieser Name taucht im ODBC auf
;-FOLGENDE ZEILE ANPASSEN
UID$="USER_ID" ; UserId
;-FOLGENDE ZEILE ANPASSEN
PWD$="PASSWORT" ;Passwort
ATTRIB$="DSN="+DSN$+";"+crlf
ATTRIB$=ATTRIB$+"DESCRIPTION="+DESCRIPTION$+";"+crlf
ATTRIB$=ATTRIB$+"SERVER="+SERVER$+";"+crlf
ATTRIB$=ATTRIB$+"ADDRESS="+ADDRESS$+";"+crlf
ATTRIB$=ATTRIB$+"NETWORK="+Network$+";"+crlf
ATTRIB$=ATTRIB$+"DATABASE="+DATABASE$+";"+crlf
ATTRIB$=ATTRIB$+"StatsLog_On="+STATSLOG_ON$+";"+crlf
ATTRIB$=ATTRIB$+"StatsLogFile="+STATSLOGFILE$+";"+crlf
ATTRIB$=ATTRIB$+"QueryLog_on="+QUERYLOG_ON$+";"+crlf
ATTRIB$=ATTRIB$+"QueryLogFile="+QUERYLOGFILE$+";"+crlf
ATTRIB$=ATTRIB$+"QueryLogTime="+QUERYLOGTIME$+";"
maxx = GetSystemMetrics_(#SM_CXSCREEN)
maxy = GetSystemMetrics_(#SM_CYSCREEN)
bor = GetSystemMetrics_(#SM_CXSIZEFRAME)
winwidth = 300
If winwidth>maxx
winwidth=maxx
EndIf
winwidth=winwidth-bor*2
winheight = 200
winleft=maxx-winwidth-bor*2 ;ganz rechts
wintop=0
dropped=#False
#WINDOW=0
#SHOWINFO=101
#OKBUT=200
OpenWindow(0, winleft, wintop, winwidth, winheight, #PB_Window_SystemMenu , DRIVER$)
CreateGadgetList(WindowID())
StringGadget(#SHOWINFO,0,0,winwidth,winheight,"",#PB_String_MultiLine)
Showinfo("Anmelden mit folgenden Parametern an "+DRIVER$)
If MakeConnection(DRIVER$,ATTRIB$)
If InitDatabase()
If OpenDatabase(0, DSN$,UID$, PWD$)
Showinfo("ODBC:ok - DB:angemeldet: User:angemeldet - Status:OK")
While WindowEvent():Wend
MessageRequester(DRIVER$,"ODBC:ok - DB:angemeldet: User:angemeldet - Status:OK",0)
If DeleteConnection(DRIVER$,DSN$)
Showinfo("DB ist wieder abgemeldet")
Showinfo("Beenden")
MessageRequester(DRIVER$,"Beenden",0)
End
Else
Showinfo("DB konnte nicht abgemeldet werden")
EndIf
Else
Showinfo("ODBC EINTRAG VORHANDEN?")
Showinfo("MS-SQL-SERVER VORHANDEN?")
Showinfo("USER GÜLTIG?")
Showinfo("PASSWORT GÜLTIG?")
MessageRequester(DRIVER$,"Beenden",0)
End
EndIf
Else
Showinfo("DB kann nicht geöffnet werden")
EndIf
Else
Showinfo("DB ist nicht angemeldet")
MessageRequester(DRIVER$,"DB ist nicht angemeldet",0)
EndIf
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow ; If the user has pressed on the close button
End
EndSelect
ForEver
; ExecutableFormat=Windows
; FirstLine=1
; EOF
Posted: Thu Apr 06, 2006 12:32 pm
by jb
I also found this code sample here on the forums written by gnozal:
http://www.purebasic.fr/english/viewtopic.php?t=16474
I hope this is of some help to you.
Posted: Thu Apr 06, 2006 4:11 pm
by dmb
Thanks for your answers so far. I'll look at the examples soon.
I've been testing a bit myself and found that I can use the command:
OpenDatabase(0,"dsn name", "userid", "password")
The only thing missing here is the ability to specify the database name, like f.e. '150'.
Is database support improved in 4.00. Afaik as a non-registrated user I cannot try 4.00 right?. If I can, please let me know how. Thanks.
Posted: Thu Apr 06, 2006 4:19 pm
by GedB
This post gives an example of an embedded flash control
http://www.purebasic.fr/english/viewtop ... sh+activex
This post gives an example of using ADO
http://www.purebasic.fr/english/viewtop ... do+activex
As you can see from both, using COM isn't easy.
Posted: Thu Apr 06, 2006 4:21 pm
by GedB
The readme for 4.00 is freely available.
http://freak.purearea.net/v4/ReadMe.html#Database
Sadly, there are no serious changes to the Database library.
Posted: Thu Apr 06, 2006 6:00 pm
by Fred
dmb: the database name should be put in the DSN no ?
Posted: Thu Apr 06, 2006 6:55 pm
by dmb
Fred wrote:dmb: the database name should be put in the DSN no ?
The DSN itself doesn't contain a reference to a particular database name. The database type to which I want to connect to is SQLBase. When using VB6 I use the following connection string:
DSN=Name of DSN;UID=userid;PWD=password;DB=database_name
As the database-server of SQLBase can manage about 100.000 different databases, I must have a way to specify the database name/number. Creating a seperate DSN for each one, isn't an option for me.
So, my wish is to have the following command .... :
OpenDatabase(0,"dsn name", "userid", "password", "database_name")
Posted: Tue Apr 11, 2006 1:04 pm
by dmb
Fred wrote:dmb: the database name should be put in the DSN no ?
Sorry that I come back to this once more, but does your answer indicates that you're not going to add this parameter to the OpenDatabase command?.
Posted: Tue Apr 11, 2006 1:09 pm
by Fred
it will be probably added, but not in the forthcoming v4.00 release (as all is feature freezed now).