C# - Using A Trigger To Record Audit Information Vs. Stored Procedure?

Apr 19, 2010

Suppose you have the following... An ASP.NET web application that calls a stored procedure to delete a record. The table has a trigger on it that will insert an audit entry each time a record is deleted. I want to be able to record in the audit entry the username of who deleted the record. What would be the best way to go about achieving this? I know I could remove the trigger and have the delete stored procedure insert the audit entry prior to deleting but are there any other recommeded alternative?

If a username was passed as a parameter to the delete stored procedure, is there anyway to get this value in the trigger that's excuted when the record is deleted? I'm just throwing this out there...

View 4 Replies


Similar Messages:

DataSource Controls :: Maximum Stored Procedure, Function, Trigger, Or View Nesting Level Exceeded (limit 32) ?

Feb 24, 2010

I have a table with recursive relation,a function and a sp for readig data from that table:

[Code...]

When I execute sp,I got this error:Maximum stored procedure,function,trigger or view nesting level exceeded (limit 32).

View 9 Replies

Web Forms :: Gridview Updation Of Record Using Stored Procedure?

Sep 21, 2010

i have bind griview dataSource with Store procedure having join of 3 table how can i update this gridview data using stored procedure?

View 5 Replies

ADO.NET :: ExecuteNonQuery Using Stored Procedure Will Not Delete Record (SQLDataAdapter)

Sep 6, 2010

I'm using VB.net 2.0 with a SQL server (2005) backend db. I've got a very odd problem. I'm trying to use a stored procedure with a parameter to delete a record from a table. I've tested the stored procedure by running it directly from visual studio and it works fine, but when running it through my application nothing happens. There's no error and it appears to have worked but the record is not deleted.

I've checked permissions on the backend db and giving the network ASPNet account the db owner role has no effect either.

Here's the code, there are 3 layers - the webform code, then the business logic class, then the dataconnection class.

'firstly the original code that is run from the webform when the user selects to delete the record

Partial Public Class NewPerson

Inherits System.Web.UI.Page
Private newConn As New DBConnection
Private currentNewRequest As New NewRequest(newConn)
Protected Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim requestID As Integer = CInt(Me.lblRecordID.Text)
Me.currentNewRequest.newRequestID = requestID
Me.newConn.openConnection()
Me.currentNewRequest.DeleteRecord()
Me.newConn.closeConnection()
End Sub
End Class
'the business logic class that is called to set the parameters etc. The newRequestID integer is set at 19, I have checked this out.
Public Class NewRequest
Private dBConnection As DBConnection
Public newRequestID As Integer
Public Sub New(ByVal dBConnection As DBConnection)
'check params
If dBConnection Is Nothing Then
Throw New ArgumentNullException("dBConnection")
End If
Me.dBConnection = dBConnection
End Sub
Public Sub DeleteRecord()
'This sub deletes a request
With Me.dBConnection
.AddParameter("@newrequestID", SqlDbType.Int, 0, newRequestID)
.ExecNonQuerySP("sp_DeleteNewRequest")
End With
End Sub
End Class
'then the data connection class
Imports System.Data.SqlClient
Public Class DBConnection
Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand
Private _ConnectionStr As String = ConfigurationManager.ConnectionStrings("Conn").ToString
'shared connection
Dim conn As New SqlConnection(_ConnectionStr)
'the parameter is added
Public Sub AddParameter(ByVal ParamName As String, ByVal paramType As Data.SqlDbType, ByVal Paramlength As Int16, ByVal ParamValue As String)
MyComm.Parameters.Add(ParamName, paramType, Paramlength)
If ParamValue = Nothing Or ParamValue = "00:00:00" Or ParamValue = "" Then
_MyComm.Parameters(ParamName).Value = DBNull.Value
Else
_MyComm.Parameters(ParamName).Value = ParamValue
End If
End Sub
'and this is where the stored procedure is supposed to run, no errors are generated
Public Sub ExecNonQuerySP(ByVal SPName As String)
Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName
_MyComm.Connection = conn
If Not _MyTrans Is Nothing Then
_MyComm.Transaction = _MyTrans
End If
Try
_MyComm.ExecuteNonQuery()
Catch ex As Exception
Dim errorMessage As String = ex.GetType.ToString & " " & ex.Message.ToString
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = errorMessage
Throw ex
Finally
End Try
End Sub
Public Sub openConnection()
conn.Open()
End Sub
Public Sub closeConnection()
conn.Close()
End Sub
End Class

The stored procedure looks like this:

ALTER PROCEDURE sp_DeleteNewRequest
/*this sp is used to delete a new account request record*/
@newrequestID int
AS
DELETE FROM NewAccountRequest WHERE
NewRequestID = @newrequestID

View 4 Replies

Insert Stored Procedure Doesn't Create Database Record

May 16, 2010

I have the following stored procedure:

ALTER PROCEDURE Pro_members_Insert
@id int outPut,
@LoginName nvarchar(50),
@Password nvarchar(15),
@FirstName nvarchar(100),
@LastName nvarchar(100),
@signupDate smalldatetime,
@Company nvarchar(100),
@Phone nvarchar(50),
@Email nvarchar(150),
@Address nvarchar(255),
@PostalCode nvarchar(10),
@State_Province nvarchar(100),
@City nvarchar(50),
@countryCode nvarchar(4),
@active bit,
@activationCode nvarchar(50)
AS
declare @usName as varchar(50)
set @usName=''
select @usName=isnull(LoginName,'') from members where LoginName=@LoginName
if @usName <> ''
begin
set @ID=-3
RAISERROR('User Already exist.', 16, 1)
return
end
set @usName=''
select @usName=isnull(email,'') from members where Email=@Email
if @usName <> ''
begin
set @ID=-4
RAISERROR('Email Already exist.', 16, 1)
return
end
declare @MemID as int
select @memID=isnull(max(ID),0)+1 from members
INSERT INTO members (................................

When I run this page, signup.aspx, provide required fields and click submit, the page simply reloads and the database table does not reflect the newly-inserted record. How do I catch the error messages that might be returned from the sproc? how to change signup.aspx so that the insert occurs.

View 3 Replies

DataSource Controls :: Update Record After The Insert In One Stored Procedure?

Jul 2, 2010

[Code]....

After this and in the same procedure i want to update the inserted or the updated record which occared in the above code with the follwing update statment :

[Code]....

updating mark is completed successfully if the record is existed (Update Case) but if the record does not exist (new record) ... the update of the mark is not occured ..

View 4 Replies

DataSource Controls :: Check Existing Record Using Stored Procedure?

Jan 20, 2010

I am trying to use a stored procedure to insert new records from aspx page. I have created an stored procedure for that and it works fine but I want to display an error message when record exist. It does not display any error message however it does not insert when record exist. How can I display an error message when record exist flag in stored procedure -

[Code]....

View 7 Replies

DataSource Controls :: How To Record Audit Trail In EF

May 24, 2010

I have a question regarding the record audit trail with EF. Recently we have started working on a application that has to have an record audit trail.Just few tables have Guid as PK, the rest of them have Int32 standard Identity setup.

The quick solution we have found is to wire up an event handler on SavingChanges and get all Added, Deleted and Modified records. But the problem is that the Inserted records for the tables that have Int32 as PK are audited with PK value of 0.

the code for the event handler looks like this:

[Code]....

View 2 Replies

Web Forms :: How To Record Audit Message In Textbox

Mar 11, 2010

I have QuoteNumber(ddquotes.text),partnumber(txtpart),Lastmodifieddate(txtLMD) which is a time stamp on my webform.I am sending all these information to my vendaor as an email with attachment .

When i click on email button a message should be recorded in a Textbox saying so and so quotenumber,so and so partnumber has been sent on ,so and so datetime to so and so vendor.how can i acheive this with single button click.

View 3 Replies

Forms Data Controls :: Update Database Record Using GridView And Stored Procedure?

Sep 8, 2010

I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error.

I can populate values from database fine but its produce error when i click on edit link button. see the code below.

[Code]....

[Code]....

View 4 Replies

DataSource Controls :: How To Convert The Oracle Stored Procedure To Sqlserver 2005 Stored Procedure

Apr 2, 2010

This is surareddy. i nead some small clarification in the "Stored Procedure"

how to convert the oracle Stored Procedure to sqlserver2005/2008 Stored Procedure.

right now i am enhancing the project that project already developed the oracle Stored Procedure. now our company is using sqlserver 2005/2008.

how to convert the Oracle Stored Procedure to sqlserver 2005 Stored Procedure

View 4 Replies

DataSource Controls :: Do Not Use Or Call Any Stored Procedure But It Says "Could Not Find Stored Procedure 'xxxxx'?

Dec 9, 2010

Initially, I have tried to use stored procedure. But I changed my mind and preferred to call sql query in codebase with command text. However, it stills tries to find initially-called stored procedure (which is neither called or exists).I think that it is related caching. But I tried it with different browsers it did not work.What might be the reason?

View 4 Replies

SQL Server :: Have A Stored Procedure Execute Another Stored Procedure During Time Period?

Jan 28, 2011

I could probably figure this out if I tried to, but I have been working so long on code, I'm a little fried

I have a stored procedure, and I want to execute another stored procedure during a time period of lets say 1/1/2011 to 12/31/2011

How Would I accomplish this?

View 4 Replies

DataSource Controls :: Execute A Stored Procedure Within A Stored Procedure?

Jan 18, 2010

Does anybody if it is possible that a stored procedure returns rows which is the result of the execution of another sp? Something like..

[Code]....

View 11 Replies

DataSource Controls :: How To Call A Stored Procedure In Another Stored Procedure

May 13, 2010

i want to return output parameter from 1 storeprocedure. into another stored procedure.

View 7 Replies

SQL Server :: Write Code Of Stored Procedure / Create Stored Procedure And Write Select Statement In It

Nov 23, 2010

how can I create stored procedure and write my select statement in it, I know how to create dataset then put type stored procedure and assign it to the sp ... what I want is writing my sp... how can I make it ?

check the following code, this is what I want to write put I don't know where or how !

CREATE STORED PROCEDURE SP_CATEGORY

@CATEGORY VARCHAR(30)

AS

BEGIN

SELECT LATIN_NAME, ENGLISH_NAME, ARABIC_NAME, CATEGORY

FROM FLORA, CATEGORY_LIST

WHERE FLORA.CATEGORY=CATEGORY_LIST.CATEGORY_NAME AND CATEGORY_LIST.CATEGORY_NAME IN (SELECT * FROM SPLITLIST(@CATEGORY, ','))

END

where can I write this code ?!

View 5 Replies

Forms Data Controls :: Working Procedure With Varbinary From Existing Stored Procedure?

Feb 22, 2010

[Code]....

i have a stored procedure with this values and i need just to make a button that will send something to "Equip" column,how to do it? write the values on my webpage and make a button to exec the procedu

View 1 Replies

How To Create Stored Procedure In Sql Server And Call That Procedure From C# Code

Sep 1, 2010

I am trying to create the following stored procedure in sql server Lat and Lng are the parameters being passed from c# code behind .But I am not able to create this stored procedureit indicates with error saying undefined column name Lat,Lng

CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( Lat/@b ) ) )
END
sqlda.SelectCommand.CommandText = "select *, spherical_distance( Lat, 57.2958, Lng) as distance
from business
[code]...

View 1 Replies

DataSource Controls :: Call One Stored Procedure In Another Procedure For Search?

May 1, 2010

I want to apply other stored procedure select query on result of first stored procedure.

View 1 Replies

SQL Server :: How To Create Stored Procedure In Sql Server 2005 And How To Use That Stored Procedure

Oct 1, 2010

I have created stored procedure and student database and also asp.net application for asp.net page but it could not found stored procedure what is the mistake actually I don't no

View 7 Replies

Forms Data Controls :: Populate Drop Down List Using Stored Stored Procedure

Mar 14, 2010

i want data to drop down list using stored procedure .

However im not able to do that.

View 3 Replies

DataSource Controls :: Stored Procedures Are Not Showing Up Correctly In The Stored Procedure Drop Down

Apr 27, 2010

I am using Visual Studio 2008 and SQL Server 2008 and have added a SQL datasource to my form.

When I configure the datasource, I choose my connection string which looks like this in my webconfig:

<connectionStrings>

<add
name="PSFSPRD_ConnectionString"
connectionString="Data

The database I am using has a schema called EQB and as such, my stored procedures are named as EQB.usp_SelectFunds, EQB.usp_SelectAccount, etc.

On the select tab of the Configure Data Source screen, I choose to use a stored procedure. The dropdown shows my stored procedures, however, the schema name does not show up in front of the stored procedures in the drop down. I see only usp_SelectFunds, usp_SelectAccount, etc.

I select one of the stored procedures and when I click TEST, I get the message that the stored procedure is not found. If I instead choose to use a SQL statement instead on the configuration screen and enter EXEC EQB.usp_SelectFunds and click TEST, it works fine.

Why are my stored procedures not showing up correctly in the stored procedure drop down and how can I fix this?

View 3 Replies

DataSource Controls :: Create Trigger Which Runs On Record Set

Mar 18, 2010

I would like to create a trigger which runs on record set and I would like to do IF UPDATE(column) on individual records.

View 3 Replies

Security :: Where The Login Information Is Stored

Feb 25, 2011

where the login information is stored in our directory?

View 4 Replies

ADO.NET :: Storing Information To Database Using Stored Procedures And Vb.net

Feb 2, 2011

I have a stored procedure which is working fine and also code in my vb class, which when I click on save, looks as though it has executed but no information is saved into the database....

My code used to save the data into the database is below.

[Code]....

View 3 Replies







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