You Can t Always Get What You Want

[Previous] [Next]

Back-end databases, OLE DB providers, ODBC drivers, CursorLocation, CursorType, LockType, CommandType, oh my! What's a database developer to do? With a little experience and a lot of reading, you'll develop a good feel for which combinations are possible and which aren't. But what happens if you do request a particular combination that's impossible? What if you request an updatable server-side static cursor? What happens if you request a client-side dynamic cursor?

As you're charting this new territory, you'll probably explore different options and experiment with code, and along the way you'll inadvertently discover the answers to questions such as these. There's one aspect of this discussion that relates to a bad joke about the difference between Microsoft Visual Basic and Visual C++ programmers: Visual Basic programmers get excited when their applications run without generating an error; Visual C++ programmers get excited when their applications simply compile. There's a kernel of truth here: it's comparatively easy to get Visual Basic code to run. But keep in mind that just because your Visual Basic code runs without generating an error, don't assume that you're getting what you asked for.

"Why didn't I get an error if I didn't get what I asked for?" you might wonder.

No, this is not a Microsoft conspiracy to placate developers. Imagine you're building an application that will access a variety of different databases. Perhaps your application will actually be an ad hoc query tool in which the user supplies the connection string, the query string, the cursor type, and so forth. In such a case, you'd probably prefer not to be required to repeatedly request a Recordset, asking for slightly less functionality each time, until you get the exact Recordset you want. You'd have a much easier time developing your code if you could pass a request to ADO for a particular type of Recordset and then examine what you actually received. This is precisely what happens.

If you ask for a client-side dynamic cursor, you'll get a static cursor without generating an error. If you ask for an updatable server-side static cursor, you'll get an updatable keyset cursor if the OLE DB provider or ODBC driver can support one. Otherwise, you'll receive a read-only cursor. Programmers with experience using RDO or the ODBC API are already familiar with this behavior.

Check the CursorType property on the Recordset after you've opened it to find out if you got the cursor type you requested. It's up to the component that's implementing the cursor to specify what type of cursor you receive.



Programming ADO
Programming MicrosoftВ® ADO.NET 2.0 Core Reference
ISBN: B002ECEFQM
EAN: N/A
Year: 2000
Pages: 131
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net