PDA

View Full Version : عدم نمایش اطلاعات در dbgrid بعد از بستن کانکشن



araelectronic@ymail.com
سه شنبه 10 آبان 1390, 13:39 عصر
با سلام

وقتی من کانکشن را میبندم اطلاعات در گرید نمایش داده نمیشه و وقتی کانکشن را باز میگذارم مشکلی پیش نمیاد .
میخواستم بدونم تو دلفی 2010 بعد از استفاده از کانکشن دیتابیس باید آنرا بست یا مانند VB6 در آخر برنامه باید بست ؟

اینهم کد من :


dm4.adoquery11.Connection:=dm4.con;

with dm4.adoquery11 do
begin
close;
sql.Clear;
sql.Add('select emp_firstname,emp_lastname,emp_Id from EMPLOYEES where emp_firstname like "'+edit23.Text +'%"') ;
open;
end;
if dm4.adoquery11.RecordCount >=1 then
begin
DataSource2.DataSet:=dm4.adoquery11;
DBGrid1.DataSource:= DataSource2;
end
dm4.adoquery11.clos



با تشکر

vcldeveloper
سه شنبه 10 آبان 1390, 14:57 عصر
وقتی کانکشن رو می بندید، تمامی دیتا ست های متصل به آن هم بسته میشند. اگر دیتاستی بسته بشه، داده های موجود در آن هم از حافظه خارج میشه. هر کنترلی (مثلا گرید) که به اون دیتاست متصل باشه هم بر اثر این موضوع، داده ایی رو نمایش نمیده؛ چون داده ایی دیگه نیست که نمایش داده بشه.

اگر میخواید با داده ها به صورت آفلاین کار کنید؛ راه های مختلفی برای این کار هست؛ یکیش استفاده از In memory datasets مثل ClientDataset هست، که می تونند داده هایی رو فارغ از اتصال داشتن یا نداشتن به بانک اطلاعاتی در حافظه نگه داری کنند. برای ADO یک راه هم این هست که نوع lock به BatchOptimistic تغییر داده بشه، و بعد از دریافت داده ها از بانک، مقدار خصوصیت Connection اون دیتاست Nil بشه (نه اینکه کانکشن بسته بشه). اینطوری اون دیتاست از کانکشن مربوطه جدا میشه، و بسته شدن کانکشن روی اون اثری نداره، ولی هر زمان که بخواید تغییرات را در بانک ثبت کنید، باید دوباره به خاصیت Connection مقدار بدید، و متد UpdateBatch اون دیتاست را برای ارسال تغییرات به بانک فراخوانی کنید.


میخواستم بدونم تو دلفی 2010 بعد از استفاده از کانکشن دیتابیس باید آنرا بست یا مانند VB6 در آخر برنامه باید بست ؟
هر زمانی که بهش نیاز ندارید، می تونید اون رو ببندید. اما باز و بسته کردن های مکرر کانکشن خودش میتونه برای موتور بانک اطلاعاتی و برنامه سربار محسوب بشه.

araelectronic@ymail.com
چهارشنبه 11 آبان 1390, 00:15 صبح
جناب کشاورز با تشکر از جواب شما ، پس با این حساب کانکشن را در اول برنامه باز کنیم و با پایان برنامه آنرا ببنذیم ایرادی پیش نمی آید؟
در ado.net هربار بعد از استفاده از کانکشن آنرا می بندیم من شنیده بودم که اینکار باعث میشه که کانکشنهای دیتابیس اشغال نباشن و امکان اتصال کلاینتهای بیشتری فراهم میشه ، آیا این دزست هست و اگر درست هست در دلفی native این امر به چه شکل بایر انجام شود ؟

با تشکر

vcldeveloper
سه شنبه 17 آبان 1390, 23:08 عصر
در ado.net هربار بعد از استفاده از کانکشن آنرا می بندیم من شنیده بودم که اینکار باعث میشه که کانکشنهای دیتابیس اشغال نباشن و امکان اتصال کلاینتهای بیشتری فراهم میشه ، آیا این دزست هست و اگر درست هست در دلفی native این امر به چه شکل بایر انجام شود ؟
نحوه انجامش را در پست قبلی توضیح دادم.

rayangostar_co
یک شنبه 12 آذر 1391, 13:58 عصر
با سلام خدمت آقای کشاورز

لطفا بیشتر توضیح بدید در مورد

mohsen24000
یک شنبه 12 آذر 1391, 18:36 عصر
LockType
The LockType property tells the provider what type of locks should be placed on records during editing. Locking can prevent one user from reading data that is being changed by another user, and it can prevent a user from changing data that is about to be changed by another user.

Modifying a record in an Access database locks some neighboring records. This is because Access uses, so called, page locking strategy. This means that if a user is editing a record, some other user won't be allowed to modify that record, or even to modify the next few records after or before it.

In Delphi, the TADOLockType specifies the types of locks that can be used. You can control row and page locking by setting the appropriate cursor lock option. To use a specific locking scheme, the provider and database type must support that locking scheme.

ltOptimistic
Optimistic locking locks the record only when it's physically updated. This type of locking is useful in conditions where there is only a small chance that a second user may update a row in the interval between when a cursor is opened and the row is finally updated. The current values in the row are compared with the values retrieved when the row was last fetched.

ltPessimistic
Pessimistic locking locks each record while it's being edited. This option tells ADO to get an exclusive lock on the row when the user makes any change to any column in the record. The ADOExpress components don't directly support pessimistic record locking because ADO itself does not have any way to arbitrarily lock a given record and still support navigating to other records.

ltReadOnly
Read only locking simply does not allow data editing. This lock is useful in conditions where your application must temporarily prevent data changes, but still can allow unrestricted reading. Read only locking with CursorType set to ctForwardOnly is ideal for reporting purposes.
ltBatchOptimistic
BatchOptimistic locking is used with disconnected recordsets. These recordsets are updated locally and all modifications are sent back to the database in a batch.