Tải bản đầy đủ - 0 (trang)
Hack 82. Allow Users to Choose a Back-End Database

Hack 82. Allow Users to Choose a Back-End Database

Tải bản đầy đủ - 0trang

Figure8-18.Selectingadatabaseconnection



Thevalueofthecomboboxisusedincodetosetthe

ConnectionpropertyforanADOconnectionobject,likethis:

DimconnAsADODB.Connection

Setconn=NewADODB.Connection

conn.ConnectionString=Me.cmbConnections

conn.Open



Inthismanner,userscaneasilychangethedatabasetheyare



workingwithatwill.



Hack83.OverridetheTimeoutInterval



Inabusynetworkenvironment,alittlepatienceis

sometimesnecessary.

WhenusingAccesstoconnecttoanexternaldatabase,

performancedependsonanumberoffactors.Oneoftheseis

thenetworkspecificallyinregardtobandwidthandtraffic.

Bandwidthmightbeconstant,butaddinthedynamicof

networktraffic,andyouoftendon'tknowwhattoexpect.

Tobeonthesafesideofhavingyourprocessingcomplete,even

ifittakesawhilelonger,youcanturnofftheADOCommandTimeout

property.Thedefaultisforatimeouttooccurafter30seconds.

Thismeansthatiftheserverhasnotcommunicatedbackto

yourapplicationin30seconds,yourapplicationassumesa

responseisn'tcoming.Youmightthenseeatimeoutmessage

suchastheoneshowninFigure8-19.



Figure8-19.Atimeoutexpirederrormessage



Settingthetimeoutintervalto0turnsoffthisproperty.Your

applicationwillthenwaitindefinitelyforaresponse.Assuming



anADOconnectionobjectnamedconnisbeingused,thisishow

youapplythesetting:

conn.CommandTimeout=0



Thedrawbacktothisapproachisthatyoureallymightwait

forever.Bytheverynatureofturningoffthetimeout,youhave

nospecificperiodofreasonabletimetoexpectforthe

processingtocomplete.Ifsomeonepulledtheplugonthe

server,youmightnotknowit.Ifitmakessense,though,you

canexperimentwithdifferentsettings.Notethatthevalueused

isinseconds,soavalueof300setsthetimeoutintervaltofive

minutes.Knowingthewaitisnomorethanfiveminutesfor

successorfailuremightmakemoresensethanwaiting

indefinitely.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 82. Allow Users to Choose a Back-End Database

Tải bản đầy đủ ngay(0 tr)

×