Re: vfp9 and sql server express

Author: Rafael Copquin

Posted: 2009-05-12 at 16:03:48

After many tries, I finally succeeded to share a connection for cursor

adapters.

In the load event of a form I do this:

thisform.nHandle = SQLConnect([TEST]) && named connection (TEST)

I create several adapter methods in the form, one for each cursor adapter I

want to generate and set all the applicable properties manually (ie,

updatenamelist, updatablefieldlist, keyfieldlist, select command)

The following properties, for each one of the cursor adapters thus created,

should read like this:

thisform.oCA .DataSourceType = "ODBC"

thisform.oCA .datasource = thisform.nHandle

thisform.oCA1 .DataSourceType = "ODBC"

thisform.oCA1 .datasource = thisform.nHandle

( a different object for each CA, ie oCA1,oCA2, etc.)

For each one of the cursor adapters I capture the connection handle, just to

verify that they all use the same connection and put them in textboxes on

the form:

thisform.text1.Value = CursorGetProp("ConnectHandle" ,'curClientes')

thisform.text2.Value = CursorGetProp("ConnectHandle" ,'curArticulos')

etc

That's all there is to it !

When the form instantiates, I can see in the textboxes that both CA's share

the same connection.

By the way, if I issue the following statement, I get a VFP message saying

that the property is readonly

SQLSetProp(0,"Shared",.T.)

(why would a property supposedly to be set by SQLSetProp be readonly? If it

cannot be set, why is it a property of a setting function? I can't

understand that.)

Now that I use one single connection for all CA's I can use transactions on

the server, like this:

** form SAVE method

#DEFINE DB_TRANSAUTO 1 && from foxpro.h

#DEFINE DB_TRANSMANUAL 2

Local lOK

SQLSetProp(thisform.nHandle, "TRANSACTIONS", DB_TRANSMANUAL)

lOK = .f.

If TableUpdate(.t.,.f.,'curClientes')

If TableUpdate(.t.,.f.,'curArticulos')

lOK = .t.

EndIf

EndIf

If lOK = .t.

SQLCommit(thisform.nHandle)

Else

SQLRollback(thisform.nHandle)

endif

SQLSetProp(thisform.nHandle, "TRANSACTIONS", DB_TRANSAUTO)

Rafael Copquin

----- Original Message -----

From: "Grigore Dolghin" <gdolghin@gmail.com>

To: <profoxtech@leafe.com>

Sent: Thursday, April 30, 2009 7:32 PM

Subject: Re: vfp9 and sql server express

Issue the following line somewhere in the beginning of your program

(before connecting to SQL Server):

SQLSetProp(0,"Shared",.T.)

This will force VFP to force first connection that will be made to be

shared.

©2009 Rafael Copquin