Page 1 of 3

Looking for library to access MS SQL server

Posted: Tue Apr 11, 2006 2:00 pm
by jqn
Hi,
Someone know a DLL or embeded LIB to access MS SQL server, using CallFunction() or CallCFunction()?.

I'm using libmysql.dll to access MySQL server, and it runs fine. I'm looking for some similar library.

Free, of course, I know already www.sqlapi.com by $299.

Best Regards
JOAQUIN

Posted: Tue Apr 11, 2006 2:18 pm
by Fangbeast

Posted: Tue Apr 11, 2006 2:28 pm
by jqn
Thanks, Fangbeast. But I'm ALREADY accessing MySQL.

I'm need same access to MicroSoft SQL server 2000. I'm looking for a dll similar to libmysql.dll.

Posted: Tue Apr 11, 2006 10:03 pm
by Fangbeast
jqn wrote:Thanks, Fangbeast. But I'm ALREADY accessing MySQL.

I'm need same access to MicroSoft SQL server 2000. I'm looking for a dll similar to libmysql.dll.
I seem to remember some code by Rings at purearea.net that would access any database. Try there or a link from there in the PBOSL libraries.

Posted: Wed Apr 12, 2006 12:04 am
by Shannara
You could try the SQL Native client DLL that comes with SQL server 2005. I heard it is backwards compatible with SQL 2000.

Posted: Wed Apr 12, 2006 12:12 am
by Tranquil
Isn't it possible to connect using ODBC?

Posted: Wed Apr 12, 2006 7:49 am
by Kukulkan
Hi jqn,

I use MySQL without any additional library. Just created a SystemDSN to MySQL and used PB-code like this (3.94):

Code: Select all

If OpenDatabase(#MySQL, mysqlUseDB.s, Username.s, Password.s) = 0
  MessageRequester("error", "MySQL-Database not available!" + #CR$ + #CR$ + DatabaseError(), #MB_ICONERROR)
  ProcedureReturn #False
EndIf

Query.s = "SELECT * FROM Table WHERE Field = Value"
If DatabaseQuery(Query.s) = 0
  MessageRequester("error", "MySQL-Error: " + DatabaseError() + " using query: '" + Query.s + "'", #MB_ICONERROR)
  ProcedureReturn #False
EndIf

(...)
There is surely no library needed!

Kukulkan

Posted: Wed Apr 12, 2006 4:36 pm
by Shannara
Tranquil wrote:Isn't it possible to connect using ODBC?
Yes, but only if you dont mind the slow down.

Posted: Wed Apr 12, 2006 4:46 pm
by Kukulkan
Yes, but only if you dont mind the slow down.
I know a lot of high performance applications using ODBC like document management systems or enterprice ressource planning. Most time, the speed is a result of your programming skills, right indexes and good logic.

But if you mean ODBC is to slow, you have to choose another method. There I can't help you. Sorry.

Kukulkan

Posted: Wed Apr 12, 2006 4:48 pm
by Fred
ODBC is a so called 'thin' wrapper, it won't be slow.

Posted: Wed Apr 12, 2006 6:35 pm
by Shannara
My apologies, I should have explained myself better.

Some people takes to practice to connect - execute sql - disconnect. When doing this through odbc in PHP, it is slow. however, having a persistant connection, it is the same speed (afaik) as using the mysql native dll.

So I actually agree too :) For persistant connections odbc and native dlls are definately compariable. but for the multiple connects/disconnects, I have found odbc slower ..

Thus is another reason why forums such as PHPBB, WWF, VB, etc have an option for persistant db connections. The speed increase is huge :)

Posted: Wed Apr 12, 2006 7:00 pm
by Shannara
On another note, if you head over to the docs found @ ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.SQL.v2005.en/dataacc9/html/69889a98-7740-4667-aecd-adfc0b37f6f0.htm

It mentions the header files found @ %PROGRAM FILES%\Microsoft SQL Server\90\SDK can be used. Specifically .. sqlncli.h :) I know there are some people here who have been successfull in converting over C headers to PB includes.

Posted: Fri Jul 21, 2006 10:51 am
by e2robot
I had the same problem and run a vb script from Purebasic to make the DSN in the ODBC control panel. Then use standard Purebasic database commands.

I basically cut and paste the code from the following site into a file called dsn.vbs

http://www.microsoft.com/technet/script ... y1110.mspx

I just use something like

Code: Select all

RunProgram("dsn.vbs","", "", 1 | 2)  
to call the script.

Phil

Posted: Fri Jul 21, 2006 12:12 pm
by Flype
Well, it can be easily done with purebasic.

Creating/Removing DSN:
http://msdn.microsoft.com/library/defau ... source.asp

Code: Select all

; flype, juil 2006 

Enumeration 1 
  #ODBC_ADD_DSN            ; Ajoute une source de données utilisateur. 
  #ODBC_CONFIG_DSN         ; Configure/Modifie une source de données utilisateur existante. 
  #ODBC_REMOVE_DSN         ; Supprime une source de données utilisateur existante. 
  #ODBC_ADD_SYS_DSN        ; Ajoute une source de données système. 
  #ODBC_CONFIG_SYS_DSN     ; Configure/Modifie une source de données système existante. 
  #ODBC_REMOVE_SYS_DSN     ; Supprime une source de données système existante. 
  #ODBC_REMOVE_DEFAULT_DSN ; Supprime la source de données définies par défaut. 
EndEnumeration 

#ODBC_DRIVER_MSACCESS = "Microsoft Access Driver (*.mdb)" 

Procedure.l MSAccess_AddConnection(name.s, database.s, hwnd.l = #Null) 
  
  Protected attrs.s 
  
  attrs + "UID="         + ";" 
  attrs + "PWD="         + ";" 
  attrs + "DSN="         + name + ";" 
  attrs + "DBQ="         + database + ";" 
  attrs + "FIL="         + "MS Access;" 
  attrs + "Driver="      + "ODBCJT32.DLL;" 
  attrs + "DefaultDir="  + GetPathPart(database) + ";" 
  attrs + "Description=" + FormatDate("Créé le %dd-%mm-%yyyy, %hh:%ii:%ss;", Date()) 
  
  ReplaceString(attrs, ";", #NULL$, 2) 
  
  ProcedureReturn SQLConfigDataSource_(hWnd, #ODBC_ADD_DSN, #ODBC_DRIVER_MSACCESS, attrs) 
  
EndProcedure 

Procedure.l MSAccess_RemoveConnection(name.s, hwnd.l = #Null) 
  
  ProcedureReturn SQLConfigDataSource_(hWnd, #ODBC_REMOVE_DSN, #ODBC_DRIVER_MSACCESS, "DSN="+name) 
  
EndProcedure 

If InitDatabase() 
  
  DSN.s = "pbtest" 
  
  If MSAccess_AddConnection(DSN, "c:\test.mdb") 
    
    If OpenDatabase(0, DSN, "", "") 
      
      If DatabaseQuery(0, "SELECT NOW") 
        If NextDatabaseRow(0) 
          Debug GetDatabaseString(0, 0) 
        EndIf 
      EndIf 
      
      If DatabaseQuery(0, "SELECT * FROM personne") 
        While NextDatabaseRow(0) 
          Debug GetDatabaseString(0, 0) 
          Debug GetDatabaseString(0, 1) 
          Debug GetDatabaseString(0, 2) 
        Wend 
      EndIf 
      
    EndIf 
    
    MSAccess_RemoveConnection(DSN) 
  
  EndIf 
  
EndIf

Posted: Sun Jul 23, 2006 4:21 am
by Beach
Kukulkan wrote:Hi jqn,

I use MySQL without any additional library. Just created a SystemDSN to MySQL and used PB-code like this (3.94):
(...)
There is surely no library needed!

Kukulkan
My 2 cents... this will not work unless the client has loaded MyODBC - which is what I primarily do when I build database driven PB apps. I usually make the connect string a registry setting so the final app could use any type of database - but I find MySQL quite capable for all the stuff I do.