unspecified error when using access

G

Guest

i have and asp.net application that uses an access database

i use dbcom for database application for ex
Imports Syste
Imports System.Dat
Imports System.Data.OleD
Imports System.Configuratio

Namespace Intranet.Common.Data.Access.Co

Public Class dbco
Implements IDisposabl
#Region "Private Fields
'connection to data sourc
Private con As OleDbConnectio
'Error Message fiel
Private _errorMessage As Strin
#End Regio

#Region "Public Properties

Public ReadOnly Property ErrorMessage() As Strin
Ge
Return _errorMessag
End Ge
End Propert

Public Shared ReadOnly Property ConnectionString() As Strin
Ge
'Return System.Configuration.ConfigurationSettings.AppSettings("Database.DEFAULT_CONNECTION_STRING"
Return System.Configuration.ConfigurationSettings.AppSettings
("ConnectionString"
End Ge
End Propert

#End Regio

#Region "Public Method Implementations

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This function takes a stored proc name and returns an integer
'by invoking ExecuteScalar() on the OleDbCommand type instance
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function RunProcedure(ByVal procName As String) As Intege
Dim result As Intege
Dim cmd As OleDbComman

Tr
cmd = CreateCommand(procName, Nothing
result = CType(cmd.ExecuteScalar(), Integer
Catch e As Exceptio
result = -
_errorMessage = e.Messag
Finall
Me.Close(
End Tr
Return resul
End Functio
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This function takes a stored proc name, sql parameters returns an integer
'by invoking ExecuteScalar() on the SqlCommand type instance
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function RunProcedure(ByVal procName As String, ByVal prams As OleDbParameter()) As Intege
Dim result As Intege
Dim cmd As OleDbComman

Tr

cmd = CreateCommand(procName, prams
result = cmd.ExecuteScalar(

Catch e As Exceptio
result = -
_errorMessage = e.Messag

Finall
Me.Close(

End Tr

Return resul

End Functio



......................................End Namespac
i use these i
Imports Syste
Imports System.Dat
Imports System.Data.OleD
Imports System.Configuratio
Imports Alliance.Intranet.Common.Data.Access.Co

Namespace Intranet.Common.Business.Logic.Co


Public Class CustomerBi

Implements IDisposabl


#Region "Private Fields
'connection to data sourc
Private con As OleDbConnectio
'Error Message fiel
Private _errorMessage As Strin
#End Regio

#Region "Public Properties

Public ReadOnly Property ErrorMessage() As Strin
Ge
Return _errorMessag
End Ge
End Propert

Public Shared ReadOnly Property ConnectionString() As Strin
Ge
'Return System.Configuration.ConfigurationSettings.AppSettings("Database.DEFAULT_CONNECTION_STRING"
Return System.Configuration.ConfigurationSettings.AppSettings
("ConnectionString"
End Ge
End Propert
#End Regio
#Region "Public Method Implementations
'********************************************************************
' CheckLogin Metho

' The CheckLogin method reads a user login and password and check
' to see if it is in the database
'*********************************************************************
Public Shared Function CheckLogIn(ByVal PlayerGameName As String, ByVal PlayerPassword As String) As OleDbDataReader
'
Dim ObjReturnDR As OleDbDataReader
Dim params(1) As OleDbParameter
Dim db As New dbcom

params(0) = db.MakeParameter("@PlayerName", PlayerGameName)
params(1) = db.MakeParameter("@PlayerPassword", PlayerPassword)
db.RunProcedure("sp_Player_CheckLogin", params, ObjReturnDR)
If ObjReturnDR Is Nothing Then
Throw New Exception(db.ErrorMessage)
End If
Return ObjReturnDR
End Function
i use similar code to insert into tables i can insert 6 records into a table and then i get unspecified error
it is not always at the same spot in the code it can and will be in different functions
any ideas this is not a big database and right now i am the only one using it(trying to test it) so there are not concurrent users
 
W

William Ryan eMVP

Janice:

I'm guessing it's on the RunProcedure line? Why not trap an OleDbException
here in RunProcedure and Debug.Assert(false, ex.ToString()) so you can find
out some information about the specifics of the problem? I also don't see
a run procedure that takes three parameters, am I missing something? You
don't need a datareader to fire executescalar or executeNonQuery and a
Reader is only useful with a connection. I'm obviously missing some code
b/c I can't see how this would work but if the connection is in this class,
then passing the reaeder to another class is probably not a good idea. In
general , DataReaders make very bad candidates for passing around and
passing them through layers is usually a disaster.

As a general design issue, are you leaving your connections open? I don't
see a connection close anywhere in there (I understand with the datareader
altough I'd caution you to rethink that whole strategy nonetheless) but
these guys need closed as soon as you are done with them and i don't see it
in here. I can't see what create command is doing but it definitely looks
unusual.

You may also want to look at the Exception strategy you have. You are
eating them but not doing anything other than returning an integer. Trapping
System.Exception has many shortcomings and I don't want to come off as
critical, but it's very very difficult to track anything down. There's very
little reason to ever trap system.Exception and this is a perfect example.
If you get a OutOfMemory exception, assuming you have a try catch block
there, do you want to send the same notification as a FileNotFoundException
or some DB specific exception? In debug, at a minimum I'd start using
Assertions to validate my assumptions and give some more detailed exception
info.
There's also a lot of unprotected code, the Me.Close in a finally block
(I'm guessing that ME is either a form or a Connection is that correct) It
would probably be better to put your return values in the try part of the
code so it's the only path that could return a value that indicates success.

I think at a minimum you need to wrap some of those pieces of code or have
something up the call stack so you know what's going on. It's really
difficult to tell from this unless I'm really missing something.

Also, if I sounded critical, please excuse me. In no way is that my intent.
it just looks like there are a few places that are potential problem areas
and I just wanted to make mention of it so hopefully they won't bite you.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
janice said:
i have and asp.net application that uses an access database.

i use dbcom for database application for ex;
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration


Namespace Intranet.Common.Data.Access.Com

Public Class dbcom
Implements IDisposable
#Region "Private Fields"
'connection to data source
Private con As OleDbConnection
'Error Message field
Private _errorMessage As String
#End Region

#Region "Public Properties"

Public ReadOnly Property ErrorMessage() As String
Get
Return _errorMessage
End Get
End Property

Public Shared ReadOnly Property ConnectionString() As String
Get
'Return System.Configuration.ConfigurationSettings.AppSettings("Database.DEFAULT_CON
NECTION_STRING")
Return
System.Configuration.ConfigurationSettings.AppSettings _
("ConnectionString")
End Get
End Property

#End Region

#Region "Public Method Implementations"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This function takes a stored proc name and returns an integer '
'by invoking ExecuteScalar() on the OleDbCommand type instance '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function RunProcedure(ByVal procName As String) As Integer
Dim result As Integer
Dim cmd As OleDbCommand

Try
cmd = CreateCommand(procName, Nothing)
result = CType(cmd.ExecuteScalar(), Integer)
Catch e As Exception
result = -1
_errorMessage = e.Message
Finally
Me.Close()
End Try
Return result
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This function takes a stored proc name, sql parameters returns an integer '
'by invoking ExecuteScalar() on the SqlCommand type instance '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function RunProcedure(ByVal procName As String, ByVal prams
As OleDbParameter()) As Integer
Dim result As Integer
Dim cmd As OleDbCommand

Try

cmd = CreateCommand(procName, prams)
result = cmd.ExecuteScalar()

Catch e As Exception
result = -1
_errorMessage = e.Message

Finally
Me.Close()

End Try

Return result

End Function



.....................................End Namespace
i use these in
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Imports Alliance.Intranet.Common.Data.Access.Com

Namespace Intranet.Common.Business.Logic.Com



Public Class CustomerBiz

Implements IDisposable



#Region "Private Fields"
'connection to data source
Private con As OleDbConnection
'Error Message field
Private _errorMessage As String
#End Region

#Region "Public Properties"

Public ReadOnly Property ErrorMessage() As String
Get
Return _errorMessage
End Get
End Property

Public Shared ReadOnly Property ConnectionString() As String
Get
'Return System.Configuration.ConfigurationSettings.AppSettings("Database.DEFAULT_CON
NECTION_STRING")
Return
System.Configuration.ConfigurationSettings.AppSettings _
("ConnectionString")
End Get
End Property
#End Region
#Region "Public Method Implementations"
'*********************************************************************
' CheckLogin Method
'
' The CheckLogin method reads a user login and password and checks
' to see if it is in the database
'*********************************************************************
Public Shared Function CheckLogIn(ByVal PlayerGameName As String,
ByVal PlayerPassword As String) As OleDbDataReader
'
Dim ObjReturnDR As OleDbDataReader
Dim params(1) As OleDbParameter
Dim db As New dbcom

params(0) = db.MakeParameter("@PlayerName", PlayerGameName)
params(1) = db.MakeParameter("@PlayerPassword", PlayerPassword)
db.RunProcedure("sp_Player_CheckLogin", params, ObjReturnDR)
If ObjReturnDR Is Nothing Then
Throw New Exception(db.ErrorMessage)
End If
Return ObjReturnDR
End Function
i use similar code to insert into tables i can insert 6 records into a
table and then i get unspecified error
it is not always at the same spot in the code it can and will be in different functions
any ideas this is not a big database and right now i am the only one
using it(trying to test it) so there are not concurrent users
 
G

Guest

Hi bil

I really appreciate your help. Your are not critical at all. I am new to asp.net. i am an old cobol programmer and just learning this stuff. Basically all the database calls are done in a dbconn class.
I found this kind of example in a Microsoft book it made the dbcomm class with the database logic then use this in a customerbiz class and call it from the asp pag
I laid out one example of how I try to insert to the database the sp_Offer_Entry is a stored procedure in access that insert
How can you do a debug.assert(….)this is new to m
if i can get an error instead of unspecified error that would be great
what happens is that i can keep inserting(with the code is seen below) somewhere between 6 and 10 records and then i get the unspecified error in another part of the program when i am using the database to get data
i am closing the connections. I understand what i am trying to do but obviously doing something wron
basically in the dbconn class i do database work in customerbiz i call my stored procedures from access and then in the asp page i call the function.
i am attaching one example of how i do an insert(this is the part that works up to a point) and then the program goes down in another part on unspecified erro

Any help you can give me on how to debug and trap errors would be greatly appreciate
In fact any help would be grea

This is the asp pag
intResult = ObjDB.AddNewOffer(intRoundID, intPlayerID, intPlayerIDContractHolder, strCooperate, strInsurance, session("RoundNumber")
bResult = ObjDB.AddToNumberOffers(Session("RoundNumber"), Session("PlayerID")

this is the customerbiz class
Imports System.Dat
Imports System.Data.OleD
Imports System.Configuratio
Imports Alliance.Intranet.Common.Data.Access.Co
Public Shared Function AddNewOffer(ByVal intRoundID As Integer, ByVal intPlayerID As Integer, ByVal intPlayerIDContractHolder As Integer, ByVal strCooperate As Boolean,
ByVal strInsurance As Boolean, ByVal intRoundNumber As Integer) As Intege
' Create and Fill the DataReade
Dim myDataReader As OleDbDataReade
Dim db As New dbco
Dim params(5) As OleDbParamete
Dim RoundID As Intege
Dim PlayerID As Intege
Dim Cooperate As Boolea
Dim Insurance As Boolea
params(0) = db.MakeParameter("@RooundID", intRoundID
params(1) = db.MakeParameter("@PlayerID", intPlayerID
params(2) = db.MakeParameter("@PlayerIDContractHolder", intPlayerIDContractHolder
params(3) = db.MakeParameter("@Cooperate", strCooperate
params(4) = db.MakeParameter("@Insurance", strInsurance
params(5) = db.MakeParameter("@RoundNumber", intRoundNumber

db.RunProcedure("sp_Offer_Entry", params, myDataReader
If myDataReader Is Nothing The
Throw New Exception(db.ErrorMessage
End I

End Functio

This is the dbcomclas
Namespace Intranet.Common.Data.Access.Co

Public Class dbco
Implements IDisposable ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This method takes a stored proc name and a OleDbDataReader (BY REF) and returns the results
'in the same DataReader that you pass in as ref. This invokes ExecuteReader on SqlCommand type
'instance
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub RunProcedure(ByVal procName As String, ByRef dataReader As OleDbDataReader
Dim cmd As OleDbComman
Tr
cmd = CreateCommand(procName, Nothing
dataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection

Catch e As Exceptio
dataReader = Nothin
_errorMessage = e.Messag
Me.Close(

End Tr
End Su
 
G

Guest

hi bil
i solved my unspecified error by putting more try catches in my code so now i actually know what is going wron

i have a question about datagrids and rebindin

i have a datagrid which is populated with name
i have a button that when clicked runs some queries and then i want to take that name out of the datagrid and rebind the datagrid less that persons name. my stored procedure is running correctly by itsel

when i click the button the record gets inserted and i run my query so this persons name should not show in the datagri

i try to rebind

my problem is that when i click the button it does not rebind. the next time i click the button that persons name is gone et
i am always one person behin

this is how i am rebinding on the clic
Sub cmd_Submit_Click(ByVal sender As Object, ByVal e As EventArgs
Dim ObjDB As New CustomerBi
Dim ObjDR As OleDbDataReade
Dim ReportDS As DataSe
Dim intResult As Intege
Dim bResult As Boolea
Dim sResult As Strin
Dim intResultOffers As Intege
Dim intPlayerID As Intege
Dim SRound As Strin
Dim intRoundID As Intege
Dim intRoundNumber As Intege
Dim sPlayerIDContractHolder As Strin
Dim intPlayerIDContractHolder As Intege
Dim strCooperate As Strin
Dim strDefect As Strin
Dim strInsurance As Strin
Dim intPlayer As Intege

tr

ReportDS = ObjDB.GetSendBid5(Session("RoundNumber"),Session("PlayerID")
Catch exc As Exceptio
response.write("The error is with GetSendBid5"
end tr
dgSendBid.DataSource = ReportD
dgSendBid.DataBind(
the getsendbid5 runs my query and then i try to rebin

any help would be greatly appreciate

thank you thank you thank yo
 
W

William Ryan eMVP

If I understand your question correctly, I don't think you need to rebind.
Once you've bound the data, it stays bound. So any changes you make to the
datasource will be reflected in the bound data, no need to rebind.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
janice said:
hi bill
i solved my unspecified error by putting more try catches in my code so
now i actually know what is going wrong
i have a question about datagrids and rebinding

i have a datagrid which is populated with names
i have a button that when clicked runs some queries and then i want to
take that name out of the datagrid and rebind the datagrid less that persons
name. my stored procedure is running correctly by itself
when i click the button the record gets inserted and i run my query so
this persons name should not show in the datagrid
i try to rebind.

my problem is that when i click the button it does not rebind. the next
time i click the button that persons name is gone etx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top