Sql - Correct Error-handling Practices For The Data-layer?

May 28, 2009

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?

View 5 Replies


ADVERTISEMENT

Migrating To Correct Practices - Get The Error Message "The Operation Could Not Be Completed"?

May 19, 2010

Time ago, I migrated to windows 7, and to get my old code running, I was forced to run Visual studio as administrator.Now I want to recode, so Visual Studio, and the program do not need to run as administrator.The first problem I get is that Visual Studio 2008 does not save the modified files without administrator rights.

Each time I try to save a file (or even run the code, which saves the files before running), I get the error message "The operation could not be completed".

it seems that I don't have rights to overwrite those files.Also, when my code crash (because I don't have administrator rights), I cannot debug. I am asked to open another instance of visual studio, but it refuses to debug, because the code is already opened.

View 6 Replies

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...

[Code]...

View 18 Replies

Exception Handling Best Practices .Net?

Dec 8, 2009

I have a general question regarding best practices for exception handling. I have a class library that uses structured error handling. The functions in the library generally perform some mathematical calculations and all return a boolean value indicating whether an exception occured or not (i.e. exception occured = true, no exception = false). The actual calculated result in the function is returned as a ByRef parameter.

Anyway the input variables for my calculations are all passed to the funtions as parameters. I perform some basic checks on these inputs (e.g check that an input is not negative etc) as part of the function code. The next stage is where im unsure of the best way to do things. Using the example i just mentioned, if an input parameter is negative, I can either throw an exception such as "ArgumentOutofRange", or i can simply show a messagebox with some info about what happened. Either way i do it the function will return true. At the moment i am throwing an exception, but on reading the "Best practices for exception handling" it is recommended you dont throw an exception for things that can be checked programatically because of "performance/overhead issues".

I'm a little confused by what they mean by this. What kind of overhead are they talking about? Slower program? More disk space required? More memory required? When my functions return true, the calling methods basically drop everything and stop calculations (exit sub), so im not sure that the overhead issues they are talking about are as important to me. It seems easier and neater to throw an exception and utilize some global error strings and pass some parameters rather than copy and paste messagebox.show() all the time, and modify the text to suit the situation. Another argument for me would be that both methods of exception handling utilize a messagebox, which stops code execution until the user does something. So i cant see the issue with the performance overhead.

View 5 Replies

VS 2008 Connect A Logic Layer Between Presentation Layer And Data Layer?

Feb 7, 2011

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.

View 4 Replies

Creating A Data Layer - Prototype An Application With A data Layer?

Jul 26, 2009

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.

View 1 Replies

Check If Input To Group Number And Number Of Units Are Correct Input By Making Error Handling Exceptions

Sep 23, 2010

Part of my assignment is to check if input to Group Number and Number of Units are correct input by making error handling exceptions...

I have to check the following:
a) group number is neither 501 nor 062
b) number of units are NOT numbers
c) number of units is NOT a positive number

So my first question is, am I checking correctly? 2nd question is, How do I make sure my Exceptions will pertain to their correct respective things (a, b, and c.. above)?

[Code]...

View 6 Replies

Error On Embedded Resources File Even Though The Data Is Correct

Mar 29, 2012

the story goes something like this:i have embedded resource file, a vbs script.i have an error when i use writeallbytes and it says dimensional error cannot be converted to bytes something like that so i decided to make a module instead of writeallbytes,what my program does is it writes the content of the script to textbox and after that this data will be written in a script and will be save on drive C: as .vbs.that is perfectly working on my codes

[Code]...

View 5 Replies

Handling DataRow Input String Was Not In A Correct Format For A Null Value?

Sep 30, 2011

I am looping through the rows of a DataRowCollection and assigning the fields of each row to a variable. I always get "Input string was not in a correct format" no matter how I cast this. I just need gapCd to contain 0 if the field is null or the value otherwise. It seems the IsDbNull is not returning true properly. I've also tried DbNull.Value comparisons with no l

View 1 Replies

VS 2010 - Correct Convention (style) For Raising And Handling Events

Apr 4, 2012

the question is really what is the correct convention (style) for raising and handling events. When a button is clicked it is generally handled by this method. [Code]

I have recently been trying to follow this convention by creating my own EventArgs class and inheriting the system.eventargs, Then adding my own properties. The problem is as my projects get bigger/complex I seem to be writing multiple eventarg classes. I then decide to try and create a generic eventarg class but this then seemed pointless thinking it would be easier just to pass the object directly instead of wrapping it up in "someEventArg" i have created.

View 4 Replies

Forms :: Error Handling - No Row At Position 0 - Need Code To Ignore Row When No Data Is Found?

Oct 6, 2011

I have a delete button in a datagridview. The button works fine however when there is nothing to delete it throws an index out of range exception. Now I know for a fact people are going to click that button even though there is nothing the I am presuming the best course of action is going to be a try/catch but I am not sure how to do it. My code is as follows,

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex <> 7 Then

[code].....

View 3 Replies

Class - Add A Readonly Property To Layer That Is Calculated Using Some Layer Information?

Nov 30, 2010

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?

View 1 Replies

Datagridview Error "System.Data.ConstraintException: Column 'Name' Is Constrained To Be Unique" Handling

Nov 13, 2009

I have a datagridview that seems to be working fine until the user adds a name into the unique name column that already exists. I am getting this: System.Data.ConstraintException: Column 'Name' is constrained to be unique. Value 'test' is already present. where and how I capture this error and prevent the users from adding another name, case insensitive, to prevent this huge error from coming up?

View 3 Replies

How To Pass List (Of ) To Data Layer Of App

Jul 25, 2011

I've never used a List(Of) before and I'm not sure how to pass it to the Data Layer of my application. The ColResCategory is a property within the Business Layer (See below) and it needs to be passed to the Data Layer. ReplaceResCategory (See 2nd Code view) is another class file within my Business Layer and the ColResCategory references it.

Public Property ColResCategory() As List(Of ReplaceResCategory)
Get
If IsNothing(mColResCategory) Then
mColResCategory = New List(Of ReplaceResCategory)
End If
Return mColResCategory
[Code] .....

View 5 Replies

How To Pass Structure Into A Data Layer

Feb 19, 2011

I'm creating a Data Layer for a Web Application and in one of my functions, I need to pass in a Structure full of Customer info. This Data Layer is essentially a DLL. My problem is that I'm not sure how to do this.Below is my code and what I want to do.

[Code]...

View 5 Replies

Sql - Improving Data Access Layer?

May 22, 2009

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.

View 5 Replies

Where To Put Calls To Data Access Layer?

Feb 20, 2009

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]

View 3 Replies

Reading App.config In Data Access Layer?

Mar 23, 2010

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.

[Code]...

View 4 Replies

VS 2005 Get A SQL Server VB Data Layer Class?

May 28, 2009

Need a SQL Server "SQLClient" (VB) Data Layer Class?

View 2 Replies

Way To Write The Data Access Layer Faster?

Oct 1, 2009

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..

View 10 Replies

What Return Type To Use In Data Access Layer

Mar 1, 2010

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.

View 5 Replies

WinForms App Data Caching - In Which Layer To Cache

Feb 27, 2009

We have data that's updated nightly in a database residing in the same instance as my app's database. So to save on database calls, I want to cache this static-for-the-day data into a List(Of MyObject). From a theory point of view, should this cached List(Of ) be cached in the presentation layer code, via a global variable? Should it be in a global variable in the .DLL?I'm thinking in the .DLL, because I created a service layer, which is exposed publicly to the GUI and makes calls to the data access layer inside the .DLL:

Public Shared Function Search(ByVal criteria As Core.Other.Customer) As List(Of Core.Other.Customer)
' TODO: Check the customer cache to see if it has been populated yet. If not, populate it.
If 1 = 1 Then

[code]....

View 3 Replies

Auto-Generate Data Layer Code With Luna?

Mar 14, 2012

If you want to go to [url]... there is a tutorial about Luna, a vb.net code generator for data Layer of application

View 6 Replies

Create An Implement Interfaces In The Data Access Layer?

Jan 15, 2010

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?

View 9 Replies

Disposing Of Custom Data Access Layer References?

Oct 1, 2010

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.

View 1 Replies

Pass Data Between BLL And UI In 3-layer (single Tier) Application?

Dec 4, 2009

I am a fairly rookie programmer who is trying to learn the basics of n-layered architecture (DAL, BLL, UI). The application I am programming is a single tier, 3-layer application written in VB.NET (.Net 3.5). Layers as follows:

DAL
BLL
UI
COMMON - contains DTO's right now.

I am having trouble determining what to pass between my BLL and UI. My instinct tells me that I should only pass data to the UI, and not the full business object from the BLL. Consider two scenarios:

1) Pass the BO directly from BLL to UI. This exposes BO methods and allows the UI direct access to the BO, which seems bad.

2) Pass only the pertinent data from the BO to the UI. For instance, a customer has a Name and Address. This data is really what we want to show/edit in the UI, so we would only return that data to the UI instead of the full BO. The UI would then call to the BLL to update a specific BO.

I am inclined to use #2, but I don't know the best way to implement it. The way I have it programmed now, if I only return data from the BLL, all references to my BO's will be lost and the GC will claim them. Based on this, I have some questions:

1) Should I keep business objects alive between calls to the BLL? The alternative is to re-create them every time I pass data through the BLL, which seems wrong.

2) What is the best way to keep a BO alive in a single tier architecture (how to hold a reference if we dont pass it to the UI?)

3) How do n-tier applications do this? Do they keep the BO's alive in the BLL and wait for an update from the UI? Doesn't this require a lot of "book keeping" in the BLL to make sure BO's are released when they are no longer needed?

View 2 Replies

Prevent Data Layer Refactoring Of ODP.NET Code And Transactions?

Aug 27, 2009

I am using Oracle 11g client, with ODP.NET. I am trying to add conditional Transaction handling.

Dim ds As New DataSet()
Dim txn As OracleTransaction
Dim _beginTransaction as Bolean = true
Using conn As New OracleConnection(ConnString)

[Code]...

How do I fix txn being nothing / null? The error is: Variable 'txn' is used before it has been assigned a value. A null reference exception could result at runtime. Edit: to RichardOD for pointing out that you can not explicitly declare that a transaction cannot be opend up on stored procedures via ODP.NET. I have verified that this is an issue. BUT We still haven't figured out why the error is occuring. I understand that txn is initially given a value w/in an if statement, but being defined outside of the try/catch block should make that irrelevant.... right? Or is that bad coding?

View 3 Replies

Build Data Layer Strongly Typed DataSets Or Classes?

Jun 22, 2012

I used to build data layer by using Classes, however someone suggest to use Strongly Typed DataSets because it's faster in development. The data layer that I'm going to build should support multi DBMS(Oracle,MSSQL, MySQL..)

View 3 Replies

C# - Build Data Layer Strongly Typed DataSets Or Classes?

Aug 17, 2009

I used to build data layer by using Classes, however someone suggest to use Strongly Typed DataSets because it's faster in development. The data layer that I'm going to build should support multi DBMS(Oracle,MSSQL, MySQL..).

how is better build it by using Strongly Typed DataSets or by using Classes?

View 3 Replies

Creating Data Access Layer - Return My Object But Not All The Fields

Jun 21, 2010

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]'.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved