Showing posts with label notifications. Show all posts
Showing posts with label notifications. 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

Saturday, February 25, 2012

Database Mail Problems / Job Notifications...

I've read an extensive bit about this problem in several forums and so far none of the information has helped me to determine if there is a bug in SQL 2005 x64 regardless of version or SP or if I just don't know how to do this correctly.

I can send a test email from db mail but when a job fails it does not send an email to an operator. I have monitored the IIS logs to see if it is trying to send and it is not. Database mail is enabled in Surface AC and in SQL Agent [one odd thing is that the 'test' button is only available on the SQL Agent Alerts page if I use SQL Mail]. No specific error happens (in the mail log, sql agent log, or application event log) when I try to send mail from a failed job. Mail accounts and credentials are valid. Please note that in the steps listed below, I have restarted the SQL Agent Service each time I make a change.

I've tried deleting and recreating the operators (they are enabled). I've tried using a mail server that uses anonymous authentication as well (I changed this back to one that uses basic authentication). The profiles were made default and public. (Though this shouldn't ever have to be done, as the account is a sysadmin) the SQLServer2005SQLAgentUser was explicitly added to the msdb DatabaseMail user role.

This query works, so I know that the job is not trying to execute the sp:

USE msdb ;

GO

EXEC dbo.sp_notify_operator

@.profile_name = N'staging monitor',

@.name = N'Charles Evans',

@.subject = N'Test Notification',

@.body = N'Successfully emailed profile.' ;

GO

This is happening in SQL 2005 x64 EE and x64 DE SP1 and SP2 respectively. Any thoughts on what else this could be? The same setup works fine in SQL 2005 SE x86 SP1.

Check the following article...

How to configure SQL Server Agent to send job status notifications and alert notifications in SQL Server 2005 64-bit editions

http://support.microsoft.com/kb/908360

|||So the only way is to use SQL Mail, instead of database mail?|||

SQL Server Agent is not integrated with Database Mail or with SQL Mail in Microsoft SQL Server 2005 64-bit editions.

Please read the article... you can setup mail using SMTP where SQL mail uses MAPI ...

|||

In SP0 this is true - according to the article:

"In SQL Server 2005 Service Pack 1 (SP1), you can use SQL Server Agent to interact with Database Mail as the mailing system on 64-bit operating systems."

I've made this work in our production system now with SP-1 EE x64, there was a permissions issue. However, things are not working in our staging environment SP-2 DE x64 with the same setup and account settings/permissions.

I'll keep posted if I figure out why not in staging.

Database Mail Operator Question

I have two jobs configured to e-mail myself on completion, but I am not currently receiving these notifications.
The SQL Agent is configured to use database mail, with a specific private profile. Of note is that the button to "Test" the mail profile is grayed out on the Alert System tab. When I execute sp_send_dbmail using the e-mail address from the operator and use the profile name defined in the SQL Agent properties, I receive an e-mail. However the jobs themselves are not sending me any e-mail.
I've also confirmed the correct name of the profile in the sysmail_profile table. The e-mail does not appear in sysmail_mailitems and sysmail_send_retries is empty. So the job notification is not getting queued.
Any ideas?
Thank-you,
Rubens
It is running under a domain account that is an administrator on the server, which is the same account the SQL Server service is running under (I haven't split them up and restricted it as is recommended).
Thank-you,
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:O6%231lsNmIHA.1208@.TK2MSFTNGP05.phx.gbl...
Hi
What account is SQL Agent running under?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23Tec6mLmIHA.3780@.TK2MSFTNGP06.phx.gbl...
I have two jobs configured to e-mail myself on completion, but I am not currently receiving these notifications.
The SQL Agent is configured to use database mail, with a specific private profile. Of note is that the button to "Test" the mail profile is grayed out on the Alert System tab. When I execute sp_send_dbmail using the e-mail address from the operator and use the profile name defined in the SQL Agent properties, I receive an e-mail. However the jobs themselves are not sending me any e-mail.
I've also confirmed the correct name of the profile in the sysmail_profile table. The e-mail does not appear in sysmail_mailitems and sysmail_send_retries is empty. So the job notification is not getting queued.
Any ideas?
Thank-you,
Rubens
|||Hmmm, come to think of it, no I wasn't. I will have to test that when back in the office tomorrow. I will let you know.
Thanks John.
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:erH9oGOmIHA.1184@.TK2MSFTNGP04.phx.gbl...
Hi
And were you logged in as this account when you tested sp_send_dbmail?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23A5C6DOmIHA.5084@.TK2MSFTNGP04.phx.gbl...
It is running under a domain account that is an administrator on the server, which is the same account the SQL Server service is running under (I haven't split them up and restricted it as is recommended).
Thank-you,
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:O6%231lsNmIHA.1208@.TK2MSFTNGP05.phx.gbl...
Hi
What account is SQL Agent running under?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23Tec6mLmIHA.3780@.TK2MSFTNGP06.phx.gbl...
I have two jobs configured to e-mail myself on completion, but I am not currently receiving these notifications.
The SQL Agent is configured to use database mail, with a specific private profile. Of note is that the button to "Test" the mail profile is grayed out on the Alert System tab. When I execute sp_send_dbmail using the e-mail address from the operator and use the profile name defined in the SQL Agent properties, I receive an e-mail. However the jobs themselves are not sending me any e-mail.
I've also confirmed the correct name of the profile in the sysmail_profile table. The e-mail does not appear in sysmail_mailitems and sysmail_send_retries is empty. So the job notification is not getting queued.
Any ideas?
Thank-you,
Rubens
|||Yes, I was able to send an e-mail using T-SQL when logged in with the account the SQL Server service / agent was using. I was able to fix the problem, although I am not sure if it's a permanent solution.
The job operator e-mail address was a distribution list on Exchange. I changed the e-mail address to include my own, ran the job, and one alert came through fine. Then I sent it only to my account, again, worked fine. I then retyped the operator e-mail address back in of the distribution list and it succeeded. The one thing I am positive of is that the e-mail address was correct right from the start because I use the same e-mail address in the Pagers section. This was and is identical to what was in the E-mail name of the operator.
Does this sound like a bug? I guess it's a little concerning considering one of the benefits of database mail is it being SMTP based and supposed to be a lot more reliable.
Thanks,
Rubens
"Rubens" <rubensrose@.hotmail.com> wrote in message news:e1A60tPmIHA.2268@.TK2MSFTNGP02.phx.gbl...
Hmmm, come to think of it, no I wasn't. I will have to test that when back in the office tomorrow. I will let you know.
Thanks John.
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:erH9oGOmIHA.1184@.TK2MSFTNGP04.phx.gbl...
Hi
And were you logged in as this account when you tested sp_send_dbmail?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23A5C6DOmIHA.5084@.TK2MSFTNGP04.phx.gbl...
It is running under a domain account that is an administrator on the server, which is the same account the SQL Server service is running under (I haven't split them up and restricted it as is recommended).
Thank-you,
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:O6%231lsNmIHA.1208@.TK2MSFTNGP05.phx.gbl...
Hi
What account is SQL Agent running under?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23Tec6mLmIHA.3780@.TK2MSFTNGP06.phx.gbl...
I have two jobs configured to e-mail myself on completion, but I am not currently receiving these notifications.
The SQL Agent is configured to use database mail, with a specific private profile. Of note is that the button to "Test" the mail profile is grayed out on the Alert System tab. When I execute sp_send_dbmail using the e-mail address from the operator and use the profile name defined in the SQL Agent properties, I receive an e-mail. However the jobs themselves are not sending me any e-mail.
I've also confirmed the correct name of the profile in the sysmail_profile table. The e-mail does not appear in sysmail_mailitems and sysmail_send_retries is empty. So the job notification is not getting queued.
Any ideas?
Thank-you,
Rubens
|||I've just noticed another issue. I've created all my maintenance plans using the wizard. When I go into the "Reporting and Logging" section for the maintenance plan, I've selected the "Send report to an email recipient" check box, the recipient being the same one that the job alert sends to. However, I am not receiving the e-mail report. Instead, I am only getting an e-mail from the job saying it has completed. I don't get a report from the maintenance plan. I have also confirmed that the logging file is created in a folder on the server.
Any idea why I am not getting this report in an e-mail?
Thank-you,
Rubens
"Rubens" <rubensrose@.hotmail.com> wrote in message news:eC7QYMXmIHA.5684@.TK2MSFTNGP03.phx.gbl...
Yes, I was able to send an e-mail using T-SQL when logged in with the account the SQL Server service / agent was using. I was able to fix the problem, although I am not sure if it's a permanent solution.
The job operator e-mail address was a distribution list on Exchange. I changed the e-mail address to include my own, ran the job, and one alert came through fine. Then I sent it only to my account, again, worked fine. I then retyped the operator e-mail address back in of the distribution list and it succeeded. The one thing I am positive of is that the e-mail address was correct right from the start because I use the same e-mail address in the Pagers section. This was and is identical to what was in the E-mail name of the operator.
Does this sound like a bug? I guess it's a little concerning considering one of the benefits of database mail is it being SMTP based and supposed to be a lot more reliable.
Thanks,
Rubens
"Rubens" <rubensrose@.hotmail.com> wrote in message news:e1A60tPmIHA.2268@.TK2MSFTNGP02.phx.gbl...
Hmmm, come to think of it, no I wasn't. I will have to test that when back in the office tomorrow. I will let you know.
Thanks John.
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:erH9oGOmIHA.1184@.TK2MSFTNGP04.phx.gbl...
Hi
And were you logged in as this account when you tested sp_send_dbmail?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23A5C6DOmIHA.5084@.TK2MSFTNGP04.phx.gbl...
It is running under a domain account that is an administrator on the server, which is the same account the SQL Server service is running under (I haven't split them up and restricted it as is recommended).
Thank-you,
Rubens
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message news:O6%231lsNmIHA.1208@.TK2MSFTNGP05.phx.gbl...
Hi
What account is SQL Agent running under?
John
"Rubens" <rubensrose@.hotmail.com> wrote in message news:%23Tec6mLmIHA.3780@.TK2MSFTNGP06.phx.gbl...
I have two jobs configured to e-mail myself on completion, but I am not currently receiving these notifications.
The SQL Agent is configured to use database mail, with a specific private profile. Of note is that the button to "Test" the mail profile is grayed out on the Alert System tab. When I execute sp_send_dbmail using the e-mail address from the operator and use the profile name defined in the SQL Agent properties, I receive an e-mail. However the jobs themselves are not sending me any e-mail.
I've also confirmed the correct name of the profile in the sysmail_profile table. The e-mail does not appear in sysmail_mailitems and sysmail_send_retries is empty. So the job notification is not getting queued.
Any ideas?
Thank-you,
Rubens

Database mail issue - any ideas?

We recently installed 2005 and have been playing with it. I seem to be
having a problem with Database Mail as it relates to job notifications,
and wanted to see if anyone knew what I was doing wrong or how to fix
this issue.
We've enabled Database Mail using the SAC tool. I've set up a mail
profile & account successfully and sent successful test messages. I
followed the instructions here (
http://msdn2.microsoft.com/en-us/library/ms186358.aspx ) on configuring
SQL Agent mail to use my Database Mail profile. But alas - no messages
ever arrive. In the SQL Agent log, I see this:
Message
[264] An attempt was made to send an email when no email session has
been established
Everything seemed rather straightforward....am I doing something wrong?
Did you run msdb.dbo.sysmail_start_sp? Try
msdb.dbo.sysmail_help_status_sp and see what the result is.
-KJ
|||The result was...
STARTED
|||You may need to define an operator.
|||I also defined an operator (myself). The operator email has the same
email address as the test message that was sent successfully, so I know
everything outside of SQL is working (SMTP relay, etc.).
|||OK - got it figured out. I just had to stop & restart the service,
which I did through SAC tool. Then I immediately received my next test
from the job.

Database mail issue - any ideas?

We recently installed 2005 and have been playing with it. I seem to be
having a problem with Database Mail as it relates to job notifications,
and wanted to see if anyone knew what I was doing wrong or how to fix
this issue.
We've enabled Database Mail using the SAC tool. I've set up a mail
profile & account successfully and sent successful test messages. I
followed the instructions here (
http://msdn2.microsoft.com/en-us/library/ms186358.aspx ) on configuring
SQL Agent mail to use my Database Mail profile. But alas - no messages
ever arrive. In the SQL Agent log, I see this:
Message
[264] An attempt was made to send an email when no email session has
been established
Everything seemed rather straightforward....am I doing something wrong?Did you run msdb.dbo.sysmail_start_sp? Try
msdb.dbo.sysmail_help_status_sp and see what the result is.
-KJ|||The result was...
STARTED|||You may need to define an operator.|||I also defined an operator (myself). The operator email has the same
email address as the test message that was sent successfully, so I know
everything outside of SQL is working (SMTP relay, etc.).|||OK - got it figured out. I just had to stop & restart the service,
which I did through SAC tool. Then I immediately received my next test
from the job.

Database mail issue - any ideas?

We recently installed 2005 and have been playing with it. I seem to be
having a problem with Database Mail as it relates to job notifications,
and wanted to see if anyone knew what I was doing wrong or how to fix
this issue.
We've enabled Database Mail using the SAC tool. I've set up a mail
profile & account successfully and sent successful test messages. I
followed the instructions here (
http://msdn2.microsoft.com/en-us/library/ms186358.aspx ) on configuring
SQL Agent mail to use my Database Mail profile. But alas - no messages
ever arrive. In the SQL Agent log, I see this:
Message
[264] An attempt was made to send an email when no email session has
been established
Everything seemed rather straightforward....am I doing something wrong?Did you run msdb.dbo.sysmail_start_sp? Try
msdb.dbo.sysmail_help_status_sp and see what the result is.
-KJ|||The result was...
STARTED|||You may need to define an operator.|||I also defined an operator (myself). The operator email has the same
email address as the test message that was sent successfully, so I know
everything outside of SQL is working (SMTP relay, etc.).|||OK - got it figured out. I just had to stop & restart the service,
which I did through SAC tool. Then I immediately received my next test
from the job.

database mail isn't working in the SQL Agent job notification

Hi,

Starting a few weeks ago I stopped receiving notifications when SQL Server Agent Jobs failed. The only error I see from the Error logs is the following: "[264] An attempt was made to send an email when no email session has been established"

I've followed all of the postings about stoping and restarting the Agent service, confirming that the database mail can send out test emails and making sure that database mail account name matches the actual SMTP account.

From my testing, I can successfully send out a test email by right-clicking on "Database Mail" - "Send Test E-Mail."

Here's my setup:
Active/Passive SQL Server 2005 Cluster.
32 bit
SS2005 SP1 installed

Database Mail worked for around 6 months and then stopped. Not sure if it's a permissions issue, patch issue or a configuration issue.

Any help resolving this would be great.

Sincerely,

Steve

Ditto for me. Standard SQL 2005 setup. Engine, AS, Integration, etc. with SP1. I've done all the troubleshooting steps detailed here because this was the closest related issue I found on the Web.
The stored proc sp_send_dbmail works. So I can craft a workaround.

I found the same issue posted under Technet here. Any ideas?

|||

Well this is a slap in the face.

My manager suggested I do a restart of the SQL Server Agent. I had tried that before but since he is the boss I did it again expecting the same results. Well as you might have guessed - its working. And not just on the development server but the production too. Can't figure it.

|||

Restarting has become my habit in debugging now thanks to this

"Restart" has been mentioned in couple threads though if you searched by your error message here (or Google)

It's really weird, SQL Mail stopped working randomly IMO, thank god this doesn't happen to SQL Server

|||

Steve,

I've seen this from time-to-time on our servers, as well. After a restart of SQL Server Agent, database mail will usually run fine for a month and then the error will come back again. It is frustrating especially when it happens on production boxes with replication, but at least it doesn't require a server reboot like SQL Mail always did when it locked up.

Sunday, February 19, 2012

Database Mail

Hi All,
sql server 2005 sp2
I am able to receive email notifications when a maintenance plan is executed
but not when the sql server agent job is executed.
According to the error log, "an attempt was made to send an email when no
email session has been established"
Any reason why it works for one but not the other?
Thanks.
JNDid you enable mail for SQL Agent? You need to configure
mail for Agent - If you view the properties for agent, go to
the Alert System window and set mail up on the screen.
-Sue
On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
<jnsimex@.hotmail.com> wrote:

>Hi All,
>sql server 2005 sp2
>I am able to receive email notifications when a maintenance plan is execute
d
>but not when the sql server agent job is executed.
>According to the error log, "an attempt was made to send an email when no
>email session has been established"
>Any reason why it works for one but not the other?
>Thanks.
>JN
>|||Yes, I have a check mark besides "Enable mail profile" and configured the
sql server agent mail properties under the Alert System to use the Database
Mail with the Mail profile that I want to use.
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:ebm9635bakqghvfrelio40l4je9gmghed9@.
4ax.com...
> Did you enable mail for SQL Agent? You need to configure
> mail for Agent - If you view the properties for agent, go to
> the Alert System window and set mail up on the screen.
> -Sue
> On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
> <jnsimex@.hotmail.com> wrote:
>
>

Database Mail

Hi All,
sql server 2005 sp2
I am able to receive email notifications when a maintenance plan is executed
but not when the sql server agent job is executed.
According to the error log, "an attempt was made to send an email when no
email session has been established"
Any reason why it works for one but not the other?
Thanks.
JNDid you enable mail for SQL Agent? You need to configure
mail for Agent - If you view the properties for agent, go to
the Alert System window and set mail up on the screen.
-Sue
On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
<jnsimex@.hotmail.com> wrote:
>Hi All,
>sql server 2005 sp2
>I am able to receive email notifications when a maintenance plan is executed
>but not when the sql server agent job is executed.
>According to the error log, "an attempt was made to send an email when no
>email session has been established"
>Any reason why it works for one but not the other?
>Thanks.
>JN
>|||Yes, I have a check mark besides "Enable mail profile" and configured the
sql server agent mail properties under the Alert System to use the Database
Mail with the Mail profile that I want to use.
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:ebm9635bakqghvfrelio40l4je9gmghed9@.4ax.com...
> Did you enable mail for SQL Agent? You need to configure
> mail for Agent - If you view the properties for agent, go to
> the Alert System window and set mail up on the screen.
> -Sue
> On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
> <jnsimex@.hotmail.com> wrote:
>>Hi All,
>>sql server 2005 sp2
>>I am able to receive email notifications when a maintenance plan is
>>executed
>>but not when the sql server agent job is executed.
>>According to the error log, "an attempt was made to send an email when no
>>email session has been established"
>>Any reason why it works for one but not the other?
>>Thanks.
>>JN
>

Database Mail

Hi All,
sql server 2005 sp2
I am able to receive email notifications when a maintenance plan is executed
but not when the sql server agent job is executed.
According to the error log, "an attempt was made to send an email when no
email session has been established"
Any reason why it works for one but not the other?
Thanks.
JN
Did you enable mail for SQL Agent? You need to configure
mail for Agent - If you view the properties for agent, go to
the Alert System window and set mail up on the screen.
-Sue
On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
<jnsimex@.hotmail.com> wrote:

>Hi All,
>sql server 2005 sp2
>I am able to receive email notifications when a maintenance plan is executed
>but not when the sql server agent job is executed.
>According to the error log, "an attempt was made to send an email when no
>email session has been established"
>Any reason why it works for one but not the other?
>Thanks.
>JN
>
|||Yes, I have a check mark besides "Enable mail profile" and configured the
sql server agent mail properties under the Alert System to use the Database
Mail with the Mail profile that I want to use.
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:ebm9635bakqghvfrelio40l4je9gmghed9@.4ax.com...
> Did you enable mail for SQL Agent? You need to configure
> mail for Agent - If you view the properties for agent, go to
> the Alert System window and set mail up on the screen.
> -Sue
> On Mon, 4 Jun 2007 11:05:22 -0400, "JN"
> <jnsimex@.hotmail.com> wrote:
>