Sample aplication on CDT 31 using ADO or OLEDB sqlserver

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
Alberto Aviles

Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Alberto Aviles » 21 Nov 2007, 19:30

 Posted by:  Alberto Aviles 

Hi NG

Some one have a sample application (in CDT 3.1) that uses ADO or OLEDB with
SqlServer (2000, express ... )
i have to migrate one application and i don't have any idea this implies that
translation!!

thanks.

Jonas Mandahl Pedersen

Re: Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Jonas Mandahl Pedersen » 03 Dec 2007, 17:54

 Posted by:  Jonas Pedersen 

Do not even consider using ADO with TD, it would be your worst nightmare.
OLEDB is fine.

Just replace the places in your code where you do Database connections with
the following code:

If SqlCreateSession( hSession,
"Provider=sqloledb;Data Source=myServerAddress;Initial
Catalog=myDataBase;User
Id=myUsername;Password=myPassword;" )
Call SqlCreateStatement( hSession, *hSql )

*hSql is the handle you use at present

You should not need to change any more code. If you use certain functions
from previous database they might need to be replaced with Sql server 2000
functions.

Jonas

Alberto Aviles

Re: Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Alberto Aviles » 03 Dec 2007, 18:45

 Posted by:  Alberto Aviles 

Jonas

thanks a lot ... I'll make a test this...

Jim McNamara

Re: Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Jim McNamara » 03 Dec 2007, 20:05

 Posted by:  Jim McNamara 

Call SqlCreateSession(...) only once for your app. (unless you call
SqlFreeSession(...) between calls to it, but create session is the time
consuming piece so do that only once if you can)

Alberto Aviles

Re: Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Alberto Aviles » 03 Dec 2007, 22:49

 Posted by:  Alberto Aviles 

mmm...
we don't use session, we connect the handler when the form is created and
disconnect when the form is close !!

some like this...

on sam_create
call conectaDB( hSqHandler1 ) // all the connectios was made with this
function !!

on sam_Close
Call sqldisconnect( hSqHandler1 )

Function: MakeTransaction
If NOT UpdateTable1 ( hSqHandler1 )
return false
If Not DeleteTable1 ( hSqHandler1 )
return false
.
.
.
return True

Function: TrigerApp
If not MakeTansaction()
call sqlprepareandexecute( hSqHandler1 , 'Roll back')
else
call sqlcommit( hSqHandler1 )

Function: ConectaDB
Description: Hace las conecciones de los hanler's con las debidas
parametrizaciones
Returns
Parameters
Receive Sql Handle: hSql
Number: nModoAislamiento
Static Variables
Local variables
String: sString
Actions
Call SalWaitCursor( TRUE )
Set bOk = FALSE
If SqlConnect(hSql)
Call SqlSetResultSet( hSql, TRUE )
!
! 1
!
If nModoAislamiento = MODO_RL
Call SqlSetIsolationLevel( hSql, 'RL' )
!
! 2
!
If nModoAislamiento = MODO_RC
Call SqlSetIsolationLevel( hSql, 'RC' )
!
! 3
!
If nModoAislamiento = MODO_RO
Call SqlSetIsolationLevel( hSql, 'RO' )
!
!
!
Call SqlSetParameter( hSql, DBP_PRESERVE , TRUE, '' )
Call SqlSetParameter( hSql, DBP_AUTOCOMMIT , FALSE, sString )
Call SqlSetParameter( hSql, DBP_ROLLBACKONTIMEOUT , FALSE, '' )
Call SqlSetLockTimeout( hSql, 15 )
Set bOk = TRUE
Else
Call SalMessageBox( 'No es posible conectar con la base de Datos',
'HANDLER', MB_IconStop )
Set bOk = FALSE
Call SalWaitCursor( FALSE)
Return bOk

Krzysztof Dorko

Re: Sample aplication on CDT 31 using ADO or OLEDB sqlserver

Post by Krzysztof Dorko » 04 Dec 2007, 22:43

 Posted by:  Krzysztof Dorko 

I recommend SqlUDL variable.
It works nice for me (SQl server 2000/2005, GTD 4.2)
In this case you should not change almost anything (at least from connection
point of view:) And only when you like to Connect with different user or to
different database you should create new session (in 99% cases you can only
change SqlUser but sometimes GTD get confused and crashes so it is safer to
create new session)

Kris

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests