Hello Grigore
Only today I could find the time to sit and try your below suggestion. I
made it work as follows:
I created a shared connection using the dataenvironment builder. Then, I
created three one table CA's using the CA builder and checked "Use existing
connection handle" for every one of them..
By running the form, I could see that the connection was in effect shared. I
guess your suggestion of using a public variable or the _screen object would
work in the same manner.
Now, I tried to create the CA's by code, ie, took them out of the DE and
built them in methods of the form, in this manner:
quote
Local cUpdateNameList,cCursorSchema,cSelectCmd,cUpdatableFieldList
text to cSelectCmd noshow pretext 15
select clienteid, codigo, dt, fechaing, razon from clientes
endtext
text to cUpdateNameList noshow pretext 15
clienteid clientes.clienteid, codigo clientes.codigo, dt clientes.dt,
fechaing clientes.fechaing, razon clientes.razon
endtext
text to cCursorSchema noshow pretext 15
clienteid i, codigo c(4), dt t, fechaing t, razon c(50)
endtext
text to cUpdatableFieldList noshow pretext 15
clienteid, codigo, dt, fechaing, razon
endtext
cSelectCmd = Chrtran( cSelectCmd, Chr(13) + Chr(10), " " )
cUpdateNameList = Chrtran( cUpdateNameList, Chr(13) + Chr(10), " " )
cCursorSchema = Chrtran( cCursorSchema, Chr(13) + Chr(10), " " )
cUpdatableFieldList = Chrtran( cUpdatableFieldList, Chr(13) + Chr(10), " " )
Use in Select('curClientes')
If not PemStatus(thisform,'oCA',5)
thisform.AddProperty('oCA')
endif
Set Multilocks on
Try
lOK = .t.
thisform.oCA = Createobject("CursorAdapter")
With thisform.oCA
.Alias = "curClientes"
.Tables = "clientes"
.useDEDataSource = .t.
.SelectCmd = cSelectCmd
.BufferModeOverride = 5
.sendupdates = .t.
.KeyFieldList = "clienteid"
.usecursorschema = .t.
.CursorSchema = cCursorSchema
.UpdateNameList = cUpdateNameList
.UpdatableFieldList = cUpdatableFieldList
.cursorfill()
.cursordetach()
Endwith
Select curClientes
Catch To oException
lOK = .f.
Messagebox("Cursor curClientes could not be created "+Chr(13)+;
"Error message: " + oException.Message)
Finally
Endtry
Return lOK
unquote
I usually create very complex CA's using the above technique, especially
when more than one table is involved in the select command, because the CA
builder will not handle this type of CA. The use of text endtext is meant
for clarity in case the statements are very long (not the case here)
I used, in the above example, the properties as were generated by the
builder, just looking at each CA property window.
The DE contains the following code in its beforeopentables method (as
generated by the DE builder):
*** Select connection code: DO NOT REMOVE
***<DataSource>
This.DataSource =
sqlstringconnect([dsn=provemet;trusted_connection=yes],.t.)
***</DataSource>
*** End of Select connection code: DO NOT REMOVE
But I cannot make the manual creation methods generate the CA's
I realize this is bothering you a lot and apologize for the inconvenience,
but you being a MVP I thought that perhaps you can really give me the
correct reply.
My final objective is to generate CA's with a unique connection handle, so
as to use the SQL Server transactions appropriately. I read in the book by
Chuck Urwiler and others:
Client-Server Applications with Visual FoxPro 6.0 and SQL Server 7.0
that VFP transactions do not work with SQLServer, so one has to use the
SQLServer transactions manually and then issue the appropriate SQLCOMMIT or
SQLROLLBACK statements. And for that, I need to have one shared connection,
right?
Thank you and regards
Rafael Copquin
----- Original Message -----
From: "Grigore Dolghin" <[email protected]>
To: <[email protected]>
Sent: Friday, May 01, 2009 6:16 PM
Subject: Re: vfp9 and sql server express
>I am sorry, my mistake. Guess that's what happens when one talks from
> (bad) memory.
>
> You are creating the connection using SQLSTRINGCONNECT() or
> SQLCONNECT(). Both commands have a lSharable parameter which, if is
> .T., allows multiple CAs to share the same connection.
> In order to achieve this you should create the connection and store
> the handle in a public variable or (better) a property of a
> permanently visible object, such as _Screen.
>
> _Screen.AddProperty("ConnectionHandle")
> _Screen.ConnectionHandle = SQLCONNECT("myDNSName",.T.)
>
> or
>
> _Screen.AddProperty("ConnectionHandle")
> _Screen.ConnectionHandle = SQLSTRINGCONNECT("ConnectionStringHere",.T.)
>
> To set the cursoradapter classes to use the previously created
> connection, open them in class designer, right click, builder, and
> check "Use existing connection handle" and enter
> _Screen.ConnectionHandle in that textbox.
>
> On Fri, May 1, 2009 at 4:51 PM, Rafael Copquin <[email protected]>
> wrote:
>> Thank you Grigore
>> But I get the message: 'the property is readonly'
>> What am I doing wrong?
>> Rafael
>>
>>
>> ----- Original Message -----
>> From: "Grigore Dolghin" <[email protected]>
>> To: <[email protected]>
>> 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.
>>
>>
>>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/000701c9cf27$f6638040$6401a...@rafaelpc
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.