Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Tuesday, March 27, 2012

Database Modification (Insert/Update/Delete) Event Notifications

Hello,

I am new to SQL Server and am building a C# application which will use a local SQL Server Express 2005installation. My application will be interacting with a DB Schema with approx 250 tables and the schema is already defined. My application is responsible for monitoring changes to the data in the DB. It must watch for all data changes in the database (Insert/Update/Delete). I am looking for a way to monitor changes to the DB data due to Insert/Update/Delete activity.

Is there a simple way in SQL Server for my application to receive events whenever the table content is modified. I have come up with a few ideas myself, for example adding trigger to each table to update an additional Event table that I could look at or even receive an Query Event on , but this swould mean creating and maitaining 750 triggers (250 tables x 3).

I can't help but feel there must be a simpler way, such as some type of SQL Audit or Monitoring feature that is already built in that could notifiy an application whenever there are DB data changes? Does such a feature exist? What would be the best way to accomplish this?

MarKGB

Trigger is invented mainly for this. If you have to audit every table, you could combine insert/update/delete event into 1 trigger. That will result in 250 triggers.|||

Hi,

if you are using SQL Server 2005 you can use the new query notification for getting the notification of changes to the database. In SQL Server 2000 I would suggest to go the way you already mentioned. Creating an event table and filling this via triggers based on the tables. Perhaps you can create a generic autiting trigger (Look in google for that there have been some samples arounf how to implement this.)

HTH, Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||

Great!, I didn't know you could combine the events to one trigger. That will certainly help reduce the amount of coding. Thanks!

Mark

|||

I did as you suggested and googled 'generic audit trigger' and got a lot of hits. In fact, I found a nice example that uses a generic CLR trigger and was able to get it working. The example can be found here:

http://sqljunkies.com/Article/4CD01686-5178-490C-A90A-5AEEF5E35915.scuk

I think using this in combination with a Query Event will give me what I am looking for.

Thanks for your help.

Mark

Sunday, February 19, 2012

DATABASE Mail Account Setup Error

When I attempt to setup a new Mail Account using the GUI I receive error:
Cannot insert the value NULL into 'servername', table
'msdb.dbo.sysmail_server'
column does not allow Nulls.
I feel in all the fields on the Account Setup Screen and put in a valid smtp
server name or the IP. Then it fails. If i run the stored proc that sets up
the account, sysmail_add_account_sp, it works. After I run the sp I go into
the modify the account and it looks just like it did when I ran the GUI.
I am running 2005 on a virtual server.
Any help would be appreciated.
On Mar 15, 1:50 pm, Thom <T...@.discussions.microsoft.com> wrote:
> When I attempt to setup a new Mail Account using the GUI I receive error:CannotinsertthevalueNULLinto'servername',tab le
> 'msdb.dbo.sysmail_server'columndoes not allow Nulls.
> I feel in all the fields on the Account Setup Screen and put in a valid smtp
> server name or the IP. Then it fails. If i run the stored proc that sets up
> the account, sysmail_add_account_sp, it works. After I run the sp I gointo
> the modify the account and it looks just like it did when I ran the GUI.
> I am running 2005 on a virtual server.
> Any help would be appreciated.
Don't use the wizard. I was having the same problem and ended up
scripting it out instead:
from: http://www.sql-server-performance.com/da_email_functionality.asp
EXECUTE msdb.dbo.sysmail_add_account_sp
@.account_name = 'Dinesh',
@.description = 'Dinesh Mail on dynanet.',
@.email_address = 'dinesh@.dynanet.com',
@.display_name = 'Dinesh Asanka',
@.mailserver_name = 'mail.dynanet.com'
Use the sysmail_add_profile procedure to create a Database Mail
profile called Dinesh Mail Profile:
EXECUTE msdb.dbo.sysmail_add_profile_sp
@.profile_name = 'Dinesh',
@.description = 'Dinesh Profile'
User the sysmail_add_profileaccount procedure to add the Database Mail
account and Database Mail profile you created in previous steps.
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@.profile_name = 'Dinesh',
@.account_name = 'Dinesh',
@.sequence_number = 1
Use the sysmail_add_principalprofile procedure to grant the Database
Mail profile access to the msdb public database role and to make the
profile the default Database Mail profile:
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@.profile_name = 'Dinesh',
@.principal_name = 'public',
@.is_default = 1 ;

DATABASE Mail Account Setup Error

When I attempt to setup a new Mail Account using the GUI I receive error:
Cannot insert the value NULL into 'servername', table
'msdb.dbo.sysmail_server'
column does not allow Nulls.
I feel in all the fields on the Account Setup Screen and put in a valid smtp
server name or the IP. Then it fails. If i run the stored proc that sets up
the account, sysmail_add_account_sp, it works. After I run the sp I go into
the modify the account and it looks just like it did when I ran the GUI.
I am running 2005 on a virtual server.
Any help would be appreciated.On Mar 15, 1:50 pm, Thom <T...@.discussions.microsoft.com> wrote:
> When I attempt to setup a new Mail Account using the GUI I receive error:CannotinsertthevalueNULLinto'servername',table
> 'msdb.dbo.sysmail_server'columndoes not allow Nulls.
> I feel in all the fields on the Account Setup Screen and put in a valid smtp
> server name or the IP. Then it fails. If i run the stored proc that sets up
> the account, sysmail_add_account_sp, it works. After I run the sp I gointo
> the modify the account and it looks just like it did when I ran the GUI.
> I am running 2005 on a virtual server.
> Any help would be appreciated.
Don't use the wizard. I was having the same problem and ended up
scripting it out instead:
from: http://www.sql-server-performance.com/da_email_functionality.asp
EXECUTE msdb.dbo.sysmail_add_account_sp
@.account_name = 'Dinesh',
@.description = 'Dinesh Mail on dynanet.',
@.email_address = 'dinesh@.dynanet.com',
@.display_name = 'Dinesh Asanka',
@.mailserver_name = 'mail.dynanet.com'
Use the sysmail_add_profile procedure to create a Database Mail
profile called Dinesh Mail Profile:
EXECUTE msdb.dbo.sysmail_add_profile_sp
@.profile_name = 'Dinesh',
@.description = 'Dinesh Profile'
User the sysmail_add_profileaccount procedure to add the Database Mail
account and Database Mail profile you created in previous steps.
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@.profile_name = 'Dinesh',
@.account_name = 'Dinesh',
@.sequence_number = 1
Use the sysmail_add_principalprofile procedure to grant the Database
Mail profile access to the msdb public database role and to make the
profile the default Database Mail profile:
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@.profile_name = 'Dinesh',
@.principal_name = 'public',
@.is_default = 1 ;

DATABASE Mail Account Setup Error

When I attempt to setup a new Mail Account using the GUI I receive error:
Cannot insert the value NULL into 'servername', table
'msdb.dbo.sysmail_server'
column does not allow Nulls.
I feel in all the fields on the Account Setup Screen and put in a valid smtp
server name or the IP. Then it fails. If i run the stored proc that sets u
p
the account, sysmail_add_account_sp, it works. After I run the sp I go into
the modify the account and it looks just like it did when I ran the GUI.
I am running 2005 on a virtual server.
Any help would be appreciated.On Mar 15, 1:50 pm, Thom <T...@.discussions.microsoft.com> wrote:
> When I attempt to setup a new Mail Account using the GUI I receive error:C
annotinsertthevalueNULLinto'servername',
table
> 'msdb.dbo.sysmail_server'columndoes not allow Nulls.
> I feel in all the fields on the Account Setup Screen and put in a valid sm
tp
> server name or the IP. Then it fails. If i run the stored proc that sets
up
> the account, sysmail_add_account_sp, it works. After I run the sp I goint
o
> the modify the account and it looks just like it did when I ran the GUI.
> I am running 2005 on a virtual server.
> Any help would be appreciated.
Don't use the wizard. I was having the same problem and ended up
scripting it out instead:
from: http://www.sql-server-performance.c...nctionality.asp
EXECUTE msdb.dbo.sysmail_add_account_sp
@.account_name = 'Dinesh',
@.description = 'Dinesh Mail on dynanet.',
@.email_address = 'dinesh@.dynanet.com',
@.display_name = 'Dinesh Asanka',
@.mailserver_name = 'mail.dynanet.com'
Use the sysmail_add_profile procedure to create a Database Mail
profile called Dinesh Mail Profile:
EXECUTE msdb.dbo.sysmail_add_profile_sp
@.profile_name = 'Dinesh',
@.description = 'Dinesh Profile'
User the sysmail_add_profileaccount procedure to add the Database Mail
account and Database Mail profile you created in previous steps.
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@.profile_name = 'Dinesh',
@.account_name = 'Dinesh',
@.sequence_number = 1
Use the sysmail_add_principalprofile procedure to grant the Database
Mail profile access to the msdb public database role and to make the
profile the default Database Mail profile:
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@.profile_name = 'Dinesh',
@.principal_name = 'public',
@.is_default = 1 ;

Database Mail

Is it possible to configure Database Mail in SQL Server 2005 to process incoming messages? For example , if you wanted to insert a record into a message table every time a mail was sent to the address sample@.widgets.not and/or possibly process some additional notifications based on the content/subject of the message. If anyone could point me to any articles (assuming it's possible) I would appreciate it.

Thanks!

Database Mail only supports sending mail in SQL Server 2005.

Friday, February 17, 2012

DataBase Log error.

Hi guys,

Toda i try to insert one row in my databse product table.....that time i got this kind of error.....

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]The log file for database 'testDatabase' is full. Back up the transaction log for the database to free up some log space.

the transaction log for the database to free up some log space.

/xxxx/yyyy/zzzzzzzzzzzz.asp, line 109

any one know about this kind of error .......pls help me......

thanks in advanseHave a look at this:
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/sqlbackuprest.mspx#EYRAE|||ever since they changed the default recovery mode from 7 to 2000 I wish they had added a screen to the setup with big flashing letters about the implications.|||Can i use following command for this one,

dbcc shrinkfile ([dbname_log])|||well you could do a dbcc shrinkfile ([dbname_log],1) but the real issue you need to address here is your recovery model and what I suspect is your non-existent disaster recovery plan.

sql2k defaults to full recovery. which means you can recover to any point in time as long as you are performing database and transaction log backups. I suspect you are either not doing this or not doing it frequently enough because if you had been your transaction log would not have filled up your drive. unless of course you have your ldf and mdf on the same drive god forbid. In which case you are just straight running out of space and you do not really care what happens if you lose a drive or a machine which will eventually happen.