Common Mistakes

Chapter 3 - Connecting to a Data Source
byJohn Kauffman, Fabio Claudio Ferracchiatiet al.?
Wrox Press ?2002

When I'm teaching, I keep a log of the errors that students make in our labs. The following are things that you might want to recheck if you're having problems.

  • Specifying the data source incorrectly. Depending on the database in question, the correct name, path, user ID, and password may need to be specified. The ADO.NET error message, though, is both polite and obvious - it will be something like Could not find file 'C:\BegASPNETdb\datastores\Southwind.mdb'.

  • Forgetting to specify namespaces, or doing so with the wrong syntax. This creates an error such as Type OleDbConnection not found.

  • Using the wrong object. Sometimes, people will try to use strConnection.Open() instead of objConnection.Open(). Once the connection object is created (objConnection), it is used in the rest of the page. The variable holding the connection string is only used to instantiate the connection object. This mistake produces errors such as The Open method is not a member of 'String'.

  • Trying to use unopened connection objects. Connection objects must be opened (not just instantiated) before they can be used. This mistake leads to clear error messages such as To use XXX object your Connection object must be Open.

  • Skipping the New keyword when declaring the connection object. This produces an error message such as Array bounds cannot appear in type specifiers.

  • Typing errors in the syntax of the connection string. You need to be careful here, as the syntax is different from normal Visual Basic syntax (spaces are allowed, arguments are separated by semicolons). This type of mistake tends to yield unhelpful error messages pointing to the Connection.Open() line, rather than the line where the connection object is declared. The most common ones are as follows:

    • Not putting a space in data source yields a message such as Could not find installable ISAM, pointing to the Connection.Open() line.

    • Using a comma instead of a semicolon to separate arguments yields an error message such as No error information available, pointing to the Connection.Open() line.

    • Forgetting a semicolon between arguments also yields an error message such as No error information available, pointing to the Connection.Open() line. This mistake might occur when you're concatenating or appending more than one argument across several lines of code.



Beginning ASP. NET 2.0 and Databases
Beginning ASP.NET 2.0 and Databases (Wrox Beginning Guides)
ISBN: 0471781347
EAN: 2147483647
Year: 2004
Pages: 263

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