Exception Handling In Base Class For Data Access Layer
Mar 14, 2010
I would like to build a base class for my SQL Data Access Layer. I have most of it based out, but have a question about how to handle errors within the base class. I have a method for ExecuteNonQuery, ExecuteReader, ect...
What are good things to check for, with respect to error-handling, when you are dealing with the data-access-layer? For example, let's assume I have this function..
Public Function UserExists(ByVal userName As String) As DataTable Dim dt As Object = Nothing Dim arSqlParameters(0) As SqlParameter
[code]....
How would you go about ensuring that your code elegantly handles anything unexpected in a situation like this?
I have admin module. This module have one master page which has the no of panels at left side. I have to make this panels visible and invisible with base control class which is constructed in VB language. I'm working with asp.net 2.0 with c# web site.
how do i construct this base control class and manage panels with Master Page on link button click event.
I am generally following this tutorial, the main differences being I'm using 2008 R2 Express and Windows Forms, he is using 2005 & ASP.NET Web Site:'m building a minimalist Windows Form project for learning purposes. So I'm using a 1-table database with 2 columns, ContactID & Name. I added a dataset file, 'ContactsDataSet.xsd' to my project and added a single minimalist table adapter with just a fill() & getdata() method.Then I added a DataGridView control and connected it to the ContactsDataSet to confirm it was working and that worked fine. I ran it and it filled up with data as expected. Everything up to this point was auto-generated code.
I already read a lot about exception handling and saw many different threads on the subject but still confused when creating class libraries like the following scenario.
Lets say i have a class library "MyClass.dll", inside the project i have two classes:
Skeleton.vb Imports System.IO Public Class Skeleton Public Function Create(ByVal resourceName As String) As String
I am working in VB.NET defining my own classes. I have 5 classes, Policy, Coverage, CoverageCollection, Layer, and LayerCollection. Policy has a bunch of data items, one of which is of type CoverageCollection. Coverage has a bunch of data items, one of which is of type LayerCollection.
Policy private id as Long private name as String[code].....
Then I do like "dim p as Policy". So, iIn order to get to properties on a Layer, I reference it like p.cov(0).lyr(0).face. What I am trying to do is add a readonly property to Layer that is calculated using some Layer information but also using something from Coverage (or even Policy). I can take this in as a parameter to the property, but I think there should be a way to get at Coverage/Policy information since I am "under" it already. Is there a way to do this?
I'm relatively new to VB.NET and am having a problem when Databinding a Class to a Forms Controls. Basically within the Class, when Setting certain String Properties I heck that they are not Null/Empty and if they are Throw an Exception. The problem occurs when I bind the properties to textboxes - when the textbox is empty I expect an error to occur (which I will handle). So does anyone have any insight or solutions into why the exceptions are not being thrown when a textbox changed to an empty string?
A condensed example follows: Dim a As New SomeClass("Random", "Text") Dim f As New SomeForm(a)
I am putting some heavy though into re-writing the data access layer in my software(If you could even call it that). This was really my first project that uses, and things were done in an improper manner. In my project all of the data that is being pulled is being stored in an arraylist. some of the data is converted from the arraylist into an typed object, before being put backinto an arraylist.Also, there is no central set of queries in the application.This means that some queries are copy and pasted, which I want to eliminate as well.This application has some custom objects that are very standard to the application, and some queries that are very standard to those objects.
I am implementing a Data Access Layer (DAL), which is basically a set of classes with (VB.NET) Shared functions to actually execute the database (CRUD) calls. I am trying to figure out the best place to place the calls to the DAL within the class hierarchy. Let me give an example.Suppose I have a class Customer, with only standard ID, Name, Address1, etc. properties and maybe an overridden ToString function or so. I also have a DAL class with Shared methods, such as:[code]Would this be "cleaner" OOP? Or is it acceptable practice to let the presentation call the Dal, passing the business objects like my previous example:[code]
Im experiencing some problems while attempting to read a connection string from an App.config file in my Data Access Layer.I added the App.Config to the DAL Class Library, and added my connection string to the connectionStrings section but when I try to read it from my DAL its Returing Nothing.
One of the time consuming factors of writing the DAL is adding and assigning paramters of teh stored procedure if ther are more than 10 parameters and must link more than 3 tables this process will take a horrible amount of time..
Im writing a data access layer for my application.There are several functions that need to return a list of items like Employee Name, and EmployeeID so it can be bound to a dropdownlist.What would be the proper datatype to return, a Dictionary?The lists only contain 2 columns, a name and id.
I am trying to prototype an application with a data layer on my computer at home using Visual Basic 2008 express edition with SQL Server Compact 3.5. My production situation at work is SQL Server 2000 and I am using Visual Basic 2005 professional for development.I am trying to write the code to create a seperate data layer. Here is my code. First the data layer:
Imports System.Data Imports[code].....
My Problem is that the data does not show up in the text boxes.
I typically dont create interfaces unless i have to, however in my current application i have to create interfaces in the Data access layer. I'm a in a minor confusion that hwo do i create those interfaces more how to implement them: the following code might make things clear:I have the following class and interface in the data access namespace
[code="vb"]Imports ConsoleApplication8.BusinessLayerImports ConsoleApplication8.DataAccessLayerImports System.DataImports System Namespace DataAccessLayer Public Class CountryGateway Implements ICountryGateway
[code]....
1. Is this way implement the interface in the data access layer? (in this case the class CountryGateway access the database.)
2. I have been told that we should create interfaces than abstract classes espcially in the data access layer, is there a particular reason for this?
Our application uses a custom DataAccessLayer class almost exclusively, and within that we do use Data Access Application Block (currently version 2). We are getting the infamous "GetOrdinal" error sporadically. We are not using out-of-method connections. We are using DAAB version 2. Below is a typical example of our DAL methods:
Public Function MyDALMethod(ByVal Param1 As Integer, ByVal Param2 As Integer) As System.Data.IDataReader Dim db As Database = DatabaseFactory.CreateDatabase()
[Code].....
My main question is should these DAL references be disposed somehow? It's a custom class written in VB.NET, so it doesn't implement IDisposable so I'm not sure if there's anything to be done or not, but we do have errors and issues (like the GetOrdinal problem) which seem to be load-related, and I'm wondering if this is part of the problem.
I'm creating my Data Access Layer and I want to return my object but not all the fields so this is the code i'm using
CODE:
I then call this method in the Business Logic Layer
CODE:
lastly I try to call in in my user interface and bind it to a DataGridView
CODE:
But I keep getting this error: Unable to cast object of type 'System.Data.Linq.DataQuery`1[VB$AnonymousType_0`3[System.String,System.String,System.String]]' to type 'System.Collections.Generic.IEnumerable`1[PP_DAL.DCProposal]'.
IN my daat access layer, the stored procedure returns value of the format "CCT1". But i need to format that value to "CCT00001". Should i do this formatting in the data access layer or in the business layer?
I need to consume data from a webservice. I am receiving xml data and using this to create objects through property setters.
In one particular case, an attribute of the object (called "is_active" and indicates whether the object is active or inactive in the application) is represented sometimes by
and at other times by <field type="BooleanField" name="is_active">True</field>
The client code requires me to represent this using integers 1 and 0. The returned string "True" or "False" results in System.FormatException, as expected.
What is the most graceful way to deal with this situation?
How would you add data source to your combobox from a combobox that is connected to the access atabase?they are both ın the same form of course and the software language ıs Visual Basic. I ve got two comboboxes that I need to connect with eachother combobox1 is showing the "itemsonsell" from the "table_items" table from my access database, the second one should show the "prices" value from "table_items" depending on which "itemsonsell" item is chosen on combobox1,I ve done the solution below,but it didnt seem to be working,it is showing all the "prices" that are under the "table_items" table's "prices" class.
I get this: Base class 'System.Windows.Forms.Panel' specified for class 'MenuButton' cannot be different from the base class 'System.Windows.Forms.UserControl' of one of its other partial types.
I need to connect Access 2007 Data base using VB.net application. (This is an AddIn working underAutodesk Inventor 2012 64 Bit).When I use a ODBC DSN (under C:WindowsSysWow64) I need to compile the application with targetas x86. But Inventor 2012 64 bit needs target as x64 or Any CPU. So ODBC - DSN not working. When I tried OLEDB as "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=database.mdb"It returns with an error Microsoft.Jet.OLEDB.4.0 not registered.
Provider=Microsoft.ACE.OLEDB.12.0; Data Source=c:database.accdb;Jet OLEDB:Database Password=password;" This also gives the same error.
I'm looking into adding some unit tests for some classes in my data access layer and I'm looking at an update routine that has no return value.It simply updates a row based on the id you provide at whichever column name you provide.Inside of this method, we collect the parameters and pass them to a helper routine which calls the stored procedure to update the table.Is there a recommended approach for how to do unit testing in such a scenario?